
Security News
Open Source Maintainers Demand Ability to Block Copilot-Generated Issues and PRs
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
jest-nock-back
Advanced tools
Record HTTP fixtures (**N**etwork M**ocks**) for your tests. This is simply a light Jest-wrapper around [Nock](https://github.com/nock/nock)'s [nock-back](https://github.com/nock/nock#nock-back) feature.
Record HTTP fixtures (Network Mocks) for your tests. This is simply a light Jest-wrapper around Nock's nock-back feature.
Heavily inspired by jest-nock
Configure Jest to setup this module.
// setup.js
import { JestNockBack } from "../src/index";
JestNockBack({
jasmine,
global
});
// jest.config.js
module.exports = {
// ...
setupFilesAfterEnv: ["./setup.ts"]
// ...
};
Write tests as normal, except for tests you will want to mock, should append .nock
to the test definition.
Works for (it
, beforeEach
et. al., though only tested for it
)
// my-test.js
import Axios from "axios";
describe("e2e", () => {
it.nock("should record fixtures for http calls", async () => {
const example = await Axios.get("https://example.com");
expect(example.status).toBe(200);
expect(example.data).toMatchSnapshot();
});
});
By default, this will hit the network and perform normally.
To record fixtures, run the tests in record
mode.
$ TEST_MODE=record jest
If a fixture is found for a given test (it.nock
), all requests will be played back
from the filesystem and it will not hit the network. If a request is not found, Nock will give a connection error. This is by design, and likely an indicator that you need to fix your test or your fixture. To rerecord, simply remove the offending fixture, and run tests in record
mode again.
This will generate fixture files in the directory you configured (test/fixtures
be default).
See here for examples of how nock
options can be used: https://github.com/nock/nock#options-1
interface IJestNockBackOptions {
defaultMode?: NockBackMode;
fixtureDir?: string;
jasmine: any;
global: any;
generateMockName?(
testTitle: string,
testPath: string,
fixtureDirectory: string
): string;
nock?: Partial<NockBackOptions>;
}
FAQs
Record HTTP fixtures (**N**etwork M**ocks**) for your tests. This is simply a light Jest-wrapper around [Nock](https://github.com/nock/nock)'s [nock-back](https://github.com/nock/nock#nock-back) feature.
The npm package jest-nock-back receives a total of 50 weekly downloads. As such, jest-nock-back popularity was classified as not popular.
We found that jest-nock-back demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Open source maintainers are urging GitHub to let them block Copilot from submitting AI-generated issues and pull requests to their repositories.
Research
Security News
Malicious Koishi plugin silently exfiltrates messages with hex strings to a hardcoded QQ account, exposing secrets in chatbots across platforms.
Research
Security News
Malicious PyPI checkers validate stolen emails against TikTok and Instagram APIs, enabling targeted account attacks and dark web credential sales.