Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update test dep, fix async test for fetch #231

Merged
merged 1 commit into from
Jul 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@
"karma-chrome-launcher": "^2.2.0",
"karma-coverage": "^1.1.1",
"karma-phantomjs-launcher": "^1.0.4",
"karma-qunit": "^1.2.1",
"karma-qunit": "^2.1.0",
"karma-sinon": "^1.0.5",
"phantomjs": "^2.1.7",
"qunitjs": "^2.4.0",
"qunit": "^2.6.1",
"sinon": "^3.2.1"
},
"dependencies": {
"@xg-wang/whatwg-fetch": "^3.0.0",
"fake-xml-http-request": "^2.0.0",
"route-recognizer": "^0.3.3",
"@xg-wang/whatwg-fetch": "^3.0.0"
"route-recognizer": "^0.3.3"
},
"jspm": {
"shim": {
Expand Down
32 changes: 17 additions & 15 deletions test/fetch_test.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
var describe = QUnit.module;
var it = QUnit.test;
var clock;

describe('pretender invoking by fetch', function(config) {
config.beforeEach(function() {
this.pretender = new Pretender();
});

config.afterEach(function() {
if (clock) {
clock.restore();
}
this.pretender.shutdown();
});

it('fetch triggers pretender', function(assert) {
assert.expect(1);
var done = assert.async();
var wasCalled;

this.pretender.get('/some/path', function() {
wasCalled = true;
return [200, {}, ''];
});

fetch('/some/path');
fetch('/some/path').then(function() {
done();
});
assert.ok(wasCalled);
});

Expand All @@ -30,7 +31,7 @@ describe('pretender invoking by fetch', function(config) {
var done = assert.async();
var val = 'unset';

this.pretender.get('/some/path', function(request) {
this.pretender.get('/some/path', function() {
return [200, {}, ''];
});

Expand All @@ -44,23 +45,25 @@ describe('pretender invoking by fetch', function(config) {
});

it('can NOT be resolved synchronously', function(assert) {
assert.expect(1);
var val = 0;
assert.expect(2);
var done = assert.async();
var val = 'unset';

this.pretender.get(
'/some/path',
function(request) {
function() {
return [200, {}, ''];
},
false
);

// This is async even we specified pretender get to be synchronised
fetch('/some/path').then(function() {
// This won't be called
assert.equal(val, 0);
val++;
assert.equal(val, 'set');
done();
});
assert.equal(val, 0);
assert.equal(val, 'unset');
val = 'set';
});


Expand Down Expand Up @@ -96,7 +99,6 @@ describe('pretender invoking by fetch', function(config) {
it('has NO Abortable fetch', function(assert) {
assert.expect(1);
var done = assert.async();
var wasCalled = false;
this.pretender.get(
'/downloads',
function(request) {
Expand All @@ -115,7 +117,7 @@ describe('pretender invoking by fetch', function(config) {
assert.ok(data, 'AbortError was not rejected');
done();
})
.catch(function(err) {
.catch(function() {
// it should execute to here but won't due to FakeXmlHttpRequest limitation
done();
});
Expand Down
Loading