Skip to content

Instantly share code, notes, and snippets.

@afeld
Created September 29, 2020 06:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save afeld/fbfab5217e44359072144430ed1b8ab0 to your computer and use it in GitHub Desktop.
Save afeld/fbfab5217e44359072144430ed1b8ab0 to your computer and use it in GitHub Desktop.
Jest+Nock setup
// 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