Skip to content

Commit

Permalink
test fallback works in sandboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
wheresrhys committed Jun 23, 2018
1 parent 8cdea87 commit 57ef886
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions test/specs/options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,26 @@ module.exports = (fetchMock, theGlobal, fetch) => {
});

it('error when configured on sandbox without fetch defined', () => {
fm.config.fallbackToNetwork = true;
const sbx = fm.sandbox();
expect(() => sbx.fetchHandler('http://it.at.there/')).to.throw();
sbx.config.fallbackToNetwork = true;
expect(() => sbx('http://it.at.there/')).to.throw();
});

it('not error when configured on sandbox with fetch defined', async () => {
fm.config.fallbackToNetwork = true;
fm.config.fetch = () => Promise.resolve(200);
const sbx = fm.sandbox();
expect(() => sbx.fetchHandler('http://it.at.there/')).not.to.throw();
sbx.config.fallbackToNetwork = true;
sbx.config.fetch = () => Promise.resolve(200);
expect(() => sbx('http://it.at.there/')).not.to.throw();
});


it('actually falls back to network when configured in a sandbox properly', async () => {
const sbx = fm.sandbox();
sbx.config.fetch = fetch;
sbx.config.fallbackToNetwork = true;
sbx.mock('http://it.at.where', 204);
const res = await sbx('http://localhost:9876/dummy-file.txt')
expect(res.status).to.equal(200);
});

});

Expand Down

0 comments on commit 57ef886

Please sign in to comment.