Skip to content

Commit

Permalink
Fixup test assertions.
Browse files Browse the repository at this point in the history
We cannot simply return the promise in the failure scenarios (since
returning a rejected promise will fail the test).  I have added
back a small assertion confirming the rejections in cases we _know_
should reject.

The CSS load failure scenario is a bit annoying/odd because we cannot
guarantee that we fail properly when the asset cannot be loaded (due
to lack of browser support for `onload`/`onerror` callbacks with the
`<link>` element).
  • Loading branch information
rwjblue committed Aug 11, 2017
1 parent 234caeb commit 96f90e8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions tests/unit/services/asset-loader-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ test('loadAsset() - js - handles failed load', function(assert) {
const service = this.subject();
const asset = { type: 'js', uri: '/unit-test.jsss' };

return service.loadAsset(asset);
return service.loadAsset(asset).catch(() => assert.ok(true, 'loadAsset should reject'));
});

test('loadAsset() - js - does not insert additional script tag if asset is in DOM already', function(assert) {
Expand Down Expand Up @@ -307,7 +307,7 @@ test('loadAsset() - css - handles successful load', function(assert) {
});

test('loadAsset() - css - handles failed load', function(assert) {
assert.expect(0);
assert.expect(1);

const service = this.subject();
const asset = { type: 'css', uri: '/unit-test.csss' };
Expand All @@ -316,9 +316,11 @@ test('loadAsset() - css - handles failed load', function(assert) {
// non-Chrome browsers to either resolve or reject (they should do something).
var isChrome = !!window.chrome && window.navigator.vendor === 'Google Inc.';
if (isChrome) {
return service.loadAsset(asset);
return service.loadAsset(asset).catch(() => assert.ok(true, 'loadAsset should reject'));
} else {
return service.loadAsset(asset);
return service.loadAsset(asset)
.then(() => assert.ok(true, 'loadAsset may resolve'))
.catch(() => assert.ok(true, 'loadAsset may reject'));
}
});

Expand Down

0 comments on commit 96f90e8

Please sign in to comment.