[node] Fix handling of response callback with no arguments; add test

This commit is contained in:
John Firebaugh
2016-02-19 17:09:09 -08:00
parent f7f89cb44a
commit 675a628aa2
2 changed files with 30 additions and 1 deletions

View File

@@ -48,7 +48,7 @@ NAN_METHOD(NodeRequest::Respond) {
mbgl::Response response;
if (info.Length() < 1) {
response.error = std::make_unique<Error>(Error::Reason::NotFound);
response.noContent = true;
} else if (info[0]->BooleanValue()) {
std::unique_ptr<Nan::Utf8String> message;

View File

@@ -290,4 +290,33 @@ test('Map', function(t) {
t.end();
});
});
t.test('request callback', function (t) {
t.test('returning an error', function(t) {
var map = new mbgl.Map({
request: function(req, callback) {
callback(new Error('request error'));
},
});
map.load(style);
map.render({ zoom: 1 }, function(err, data) {
t.ok(err, 'returns error');
t.equal(err.message, 'request error');
t.end();
});
});
t.test('returning no content for a tile', function(t) {
var map = new mbgl.Map({
request: function(req, callback) {
callback();
},
});
map.load(style);
map.render({ zoom: 1 }, function(err, data) {
t.ok(data, 'no error');
t.end();
});
});
});
});