Created
September 29, 2020 06:14
-
-
Save afeld/fbfab5217e44359072144430ed1b8ab0 to your computer and use it in GitHub Desktop.
Jest+Nock setup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ensures that there's a clean slate for each test, and that no real HTTP requests are made | |
const nock = require("nock"); | |
beforeAll(() => { | |
// ensures no requests hit live APIs | |
nock.disableNetConnect(); | |
}); | |
beforeEach(() => { | |
if (!nock.isActive()) { | |
nock.activate(); | |
} | |
}); | |
afterEach(() => { | |
nock.cleanAll(); | |
// https://github.com/nock/nock#memory-issues-with-jest | |
nock.restore(); | |
}); | |
// ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment