Skip to content
This repository has been archived by the owner on Nov 3, 2021. It is now read-only.

Commit

Permalink
Merge pull request #24243 from ddrmanxbxfr/bug_1069808
Browse files Browse the repository at this point in the history
Bug 1069808 - Make the LazyLoader.getJSON() helper invoke reject() in ca...
  • Loading branch information
rvandermeulen committed Sep 24, 2014
2 parents 997fe51 + 63b57cd commit 737738b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
28 changes: 28 additions & 0 deletions apps/sharedtest/test/unit/lazy_loader_test.js
Expand Up @@ -47,6 +47,34 @@ suite('lazy loader', function() {
});
});

test('load malformed json', function(done) {
LazyLoader.getJSON('/apps/sharedtest/test/unit/support/malformedJson')
.then(function(json) {
done(new Error('A resolve promise was returned.' +
' Expected Reject promise'));
}, function(error) {
done(function() {
assert.instanceOf(error, Error);
assert.equal(error.message,
'No valid JSON object was found (200 OK)');
});
});
});

test('load inexisting json', function(done) {
LazyLoader.getJSON('/apps/sharedtest/test/unit/support/non_existant.json')
.then(function(json) {
done(new Error('Resolve promise was returned.' +
' Expected Reject promise'));
}, function(error) {
done(function() {
assert.instanceOf(error, Error);
assert.equal(error.message,
'No valid JSON object was found (404 Not Found)');
});
});
});

test('append single js script', function(done) {
LazyLoader.load('support/inc.js', function() {
assert.equal(window.jsCount, 1);
Expand Down
3 changes: 3 additions & 0 deletions apps/sharedtest/test/unit/support/malformedJson
@@ -0,0 +1,3 @@
{
"org" "Mozilla"
}
7 changes: 6 additions & 1 deletion shared/js/lazy_loader.js
Expand Up @@ -81,7 +81,12 @@ var LazyLoader = (function() {
reject(error);
};
xhr.onload = function() {
resolve(xhr.response);
if (xhr.response !== null) {
resolve(xhr.response);
} else {
reject(new Error('No valid JSON object was found (' +
xhr.status + ' ' + xhr.statusText + ')'));
}
};

xhr.send();
Expand Down

0 comments on commit 737738b

Please sign in to comment.