diff --git a/src/node_map.cpp b/src/node_map.cpp index 9a21decd5..e8dc28110 100644 --- a/src/node_map.cpp +++ b/src/node_map.cpp @@ -102,6 +102,10 @@ NAN_METHOD(NodeMap::Load) { if (!nodeMap->isValid()) return NanThrowError(releasedMessage()); + // Reset the flag as this could be the second time + // we are calling this (being the previous successful). + nodeMap->loaded = false; + if (args.Length() < 1) { return NanThrowError("Requires a map style as first argument"); } @@ -122,6 +126,8 @@ NAN_METHOD(NodeMap::Load) { return NanThrowError(ex.what()); } + nodeMap->loaded = true; + NanReturnUndefined(); } @@ -168,6 +174,10 @@ NAN_METHOD(NodeMap::Render) { return NanThrowTypeError("Second argument must be a callback function"); } + if (!nodeMap->isLoaded()) { + return NanThrowTypeError("Style is not loaded"); + } + auto options = ParseOptions(args[0]->ToObject()); assert(!nodeMap->callback); diff --git a/src/node_map.hpp b/src/node_map.hpp index bb238ea88..d442d93bb 100644 --- a/src/node_map.hpp +++ b/src/node_map.hpp @@ -33,6 +33,8 @@ public: void renderFinished(); void release(); + + inline bool isLoaded() { return loaded; } inline bool isValid() { return valid; } static std::unique_ptr ParseOptions(v8::Local obj); @@ -60,6 +62,7 @@ private: // Async for delivering the notifications of render completion. uv_async_t *async; + bool loaded = false; bool valid = true; }; diff --git a/test/js/gzip.test.js b/test/js/gzip.test.js index 2ed0080ac..c839dd5c2 100644 --- a/test/js/gzip.test.js +++ b/test/js/gzip.test.js @@ -116,7 +116,7 @@ test('gzip', function(t) { map.release(); t.ok(err, 'returns error'); - t.equal(err.message, 'Error rendering image'); + t.ok(err.message.match(/Failed to parse/), 'error text matches'); t.end(); }); diff --git a/test/js/map.test.js b/test/js/map.test.js index 427cf586b..edeab8370 100644 --- a/test/js/map.test.js +++ b/test/js/map.test.js @@ -338,11 +338,11 @@ test('Map', function(t) { }); }); - t.skip('requires a style to be set', function(t) { + t.test('requires a style to be set', function(t) { setup(fileSource, function(map) { t.throws(function() { map.render({}, function() {}); - }, /Style is not set/); + }, /Style is not loaded/); map.release(); @@ -365,7 +365,7 @@ test('Map', function(t) { map.release(); t.ok(err, 'returns error'); - t.equal(err.message, 'Error rendering image'); + t.ok(err.message.match(/Failed to load/), 'error text matches'); t.end(); }); diff --git a/vendor/mbgl b/vendor/mbgl index d9f09596f..0955dfc19 160000 --- a/vendor/mbgl +++ b/vendor/mbgl @@ -1 +1 @@ -Subproject commit d9f09596fbaa44af9b748ff67dcf2d247e72eddb +Subproject commit 0955dfc19f30aedcc95e7e3c03c73d3dcc149c44