7 examples of 'jest mock once' in JavaScript

Every line of 'jest mock once' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
22export function mockResolvedValueOnce(mock, value) {
23 mock.mockImplementationOnce(
24 () =>
25 new Promise(resolve => {
26 process.nextTick(() => resolve(value))
27 })
28 )
29}
76get called() {
77 return this.callCount > 0;
78}
13SourceGroupsManager: jest.fn().mockImplementation(function mock() {
14 this.setImportStatus = jest.fn();
15 this.findByImportId = jest.fn();
16}),
4getSpy() {
5 return jest.fn();
6}
4export function mock(callbacks) {
5 if (consoleBak) {
6 // Can only mock console once before restore it.
7 return false;
8 }
9
10 consoleBak = {};
11
12 for (const property in callbacks) {
13 if (callbacks.hasOwnProperty(property)) {
14 consoleBak[property] = console[property];
15 console[property] = callbacks[property];
16 }
17 }
18
19 return true;
20}
48export function toHaveBeenCalledOnceWith({actual, callCount, equals, argsFor}, ...args) {
49 const count = callCount(actual) || 0;
50 const wasCalledOnce = count === 1;
51 const ok = wasCalledOnce && equals(argsFor(actual, 0), args);
52 const msg = wasCalledOnce && !ok ? ' with different arguments' : '';
53
54 return {
55 pass: ok,
56 message() {
57 return `Expect ${pp(actual)} {{not}} to have been called once but was called ${pp(count)} time(s)${msg}`;
58 },
59 };
60}
167export function laterMock(
168 createStream: <u>(...timeline: Timeline<u>) =&gt; Stream<u>,
169) {
170 return function later(time: number, value?: T): Stream {
171 return createStream(t(time), v(value as any))
172 }
173}</u></u></u>

Related snippets