|
1 | 1 | const sinon = require('sinon') |
2 | 2 |
|
| 3 | +const stubFetch = () => { |
| 4 | + sinon.stub(global, 'fetch').callsFake(() => Promise.resolve()) |
| 5 | + console.log('Stubbed fetch? ', fetch, !!fetch.restore) |
| 6 | + console.log('Stubbed global.fetch? ', global.fetch, !!global.fetch.restore) |
| 7 | +} |
| 8 | + |
| 9 | +const doAssertions = () => { |
| 10 | + console.log('(inside test) Stubbed fetch? ', fetch, !!fetch.restore) |
| 11 | + expect(fetch.restore).to.be.a('function') |
| 12 | +} |
| 13 | + |
| 14 | +const restore = () => { |
| 15 | + global.fetch.restore() |
| 16 | +} |
| 17 | + |
3 | 18 | describe.only('Travis debug test', () => { |
4 | | - beforeEach(() => { |
5 | | - // console.log('Stubbing fetch:', fetch) |
6 | | - expect(fetch).to.be.a('function') |
7 | | - sinon.stub(global, 'fetch').callsFake(() => Promise.resolve()) |
8 | | - console.log('Stubbed fetch? ', fetch, !!fetch.restore) |
9 | | - console.log('Stubbed global.fetch? ', global.fetch, !!global.fetch.restore) |
10 | | - }) |
| 19 | + describe('Working everywhere', () => { |
| 20 | + beforeEach(() => { |
| 21 | + expect(fetch).to.be.a('function') |
11 | 22 |
|
12 | | - afterEach(() => { |
13 | | - global.fetch.restore() |
| 23 | + stubFetch() |
| 24 | + }) |
| 25 | + |
| 26 | + afterEach(() => { |
| 27 | + global.fetch.restore() |
| 28 | + }) |
| 29 | + |
| 30 | + it('should show that fetch is stubbed', doAssertions) |
14 | 31 | }) |
15 | 32 |
|
16 | | - it('should show that fetch is stubbed', async () => { |
17 | | - console.log('(inside test) Stubbed fetch? ', fetch, !!fetch.restore) |
| 33 | + describe('Failing in Travis', () => { |
| 34 | + beforeEach(() => { |
| 35 | + stubFetch() |
| 36 | + }) |
| 37 | + |
| 38 | + afterEach(restore) |
| 39 | + |
| 40 | + it('should show that fetch is stubbed', doAssertions) |
18 | 41 | }) |
19 | 42 | }) |
0 commit comments