Skip to content

Commit bd2087f

Browse files
committed
Fix for node 20.12.2 bug
1 parent d7c76bd commit bd2087f

3 files changed

Lines changed: 8 additions & 53 deletions

File tree

test/bib-test.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,12 @@
1-
const sinon = require('sinon')
2-
const { fixtureForRequest } = require('./fixtures')
3-
41
let client = null
52

63
describe('Bib test', function () {
74
beforeEach(() => {
85
client = require('./make-test-client')()
9-
10-
sinon.stub(global, 'fetch').callsFake(fixtureForRequest)
11-
console.log('Stubbed fetch? ', fetch, !!fetch.restore)
126
})
137

148
afterEach(() => {
159
client = null
16-
global.fetch.restore()
1710
})
1811

1912
describe('Bibs endpoint', function () {

test/helper.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ const oauth = require('oauth')
22
const sinon = require('sinon')
33
const chai = require('chai')
44
const chaiAsPromised = require('chai-as-promised')
5-
// const { fixtureForRequest } = require('./fixtures')
5+
const { fixtureForRequest } = require('./fixtures')
66

77
chai.use(chaiAsPromised)
88
global.expect = chai.expect
@@ -18,13 +18,17 @@ beforeEach(() => {
1818
callback(error, accessToken, refreshToken, results)
1919
})
2020

21-
console.log('Stubbing fetch')
22-
// _fetchSpy = sinon.stub(global, 'fetch').callsFake(fixtureForRequest)
21+
// Fix for very weird Node 20.12.2 bug where you have to reference `fetch`
22+
// in some way before stubbing it or else the stub will not take. This is
23+
// not a bug in Node 20.11.1 nor in Node 22.1.0
24+
expect(fetch).to.be.a('function')
25+
26+
_fetchSpy = sinon.stub(global, 'fetch').callsFake(fixtureForRequest)
2327
})
2428

2529
afterEach(() => {
2630
oauth.OAuth2.prototype.getOAuthAccessToken.restore()
27-
// _fetchSpy.restore()
31+
_fetchSpy.restore()
2832
})
2933

3034
module.exports = {

test/test-test.js

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)