Lines Matching refs:mock
4 const { mock, test } = require('node:test');
6 const sum = t.mock.fn((arg1, arg2) => {
10 assert.strictEqual(sum.mock.calls.length, 0);
13 assert.strictEqual(sum.mock.calls.length, 2);
15 let call = sum.mock.calls[0];
22 call = sum.mock.calls[1];
34 const sum = t.mock.fn(bound);
36 assert.strictEqual(sum.mock.calls.length, 0);
39 assert.strictEqual(sum.mock.calls.length, 2);
41 let call = sum.mock.calls[0];
47 call = sum.mock.calls[1];
75 const ctor = t.mock.fn(Clazz);
83 assert.strictEqual(ctor.mock.calls.length, 1);
85 const call = ctor.mock.calls[0];
95 const fn = t.mock.fn();
97 assert.strictEqual(fn.mock.calls.length, 0);
99 assert.strictEqual(fn.mock.calls.length, 1);
101 const call = fn.mock.calls[0];
109 const fn1 = t.mock.fn();
111 const fn2 = t.mock.fn();
117 assert.notStrictEqual(fn1.mock, fn2.mock);
118 assert.strictEqual(fn1.mock.calls.length, 2);
119 assert.strictEqual(fn2.mock.calls.length, 1);
137 const fn1 = t.mock.fn(sum, difference);
138 const fn2 = t.mock.fn(sum, product);
146 assert.notStrictEqual(fn1.mock, fn2.mock);
147 assert.strictEqual(fn1.mock.calls.length, 1);
148 assert.strictEqual(fn2.mock.calls.length, 2);
163 t.mock.method(obj, 'foo');
165 t.mock.method(obj, 'bar');
169 assert.notStrictEqual(obj.foo.mock, obj.bar.mock);
170 assert.strictEqual(obj.foo.mock.calls.length, 1);
171 assert.strictEqual(obj.bar.mock.calls.length, 2);
193 const fn1 = t.mock.method(obj, 'sum', difference);
198 assert.notStrictEqual(fn1.mock, undefined);
199 assert.strictEqual(originalSum.mock, undefined);
200 assert.strictEqual(difference.mock, undefined);
201 assert.strictEqual(product.mock, undefined);
202 assert.strictEqual(fn1.mock.calls.length, 2);
204 const fn2 = t.mock.method(obj, 'sum', product);
209 assert.strictEqual(fn2.mock.calls.length, 1);
211 obj.sum.mock.restore();
213 obj.sum.mock.restore();
215 assert.strictEqual(obj.sum.mock, undefined);
227 t.mock.method(obj, 'method');
228 assert.strictEqual(obj.method.mock.calls.length, 0);
231 const call = obj.method.mock.calls[0];
238 assert.strictEqual(obj.method.mock.restore(), undefined);
240 assert.strictEqual(obj.method.mock, undefined);
253 const getter = t.mock.method(obj, 'method', { getter: true });
255 assert.strictEqual(getter.mock.calls.length, 0);
258 const call = getter.mock.calls[0];
265 assert.strictEqual(getter.mock.restore(), undefined);
282 const setter = t.mock.method(obj, 'method', { setter: true });
284 assert.strictEqual(setter.mock.calls.length, 0);
287 assert.strictEqual(setter.mock.calls.length, 1);
289 const call = setter.mock.calls[0];
296 assert.strictEqual(setter.mock.restore(), undefined);
303 const sum = t.mock.fn(function(arg1, arg2) {
309 assert.strictEqual(sum.mock.calls.length, 1);
311 const call = sum.mock.calls[0];
317 assert.strictEqual(sum.mock.restore(), undefined);
336 t.mock.method(obj, obj.someTask.name);
337 assert.strictEqual(obj.someTask.mock.calls.length, 0);
341 const call = obj.someTask.mock.calls[0];
351 obj2.someTask.mock,
355 assert.strictEqual(obj.someTask.mock.restore(), undefined);
357 assert.strictEqual(obj.someTask.mock, undefined);
358 assert.strictEqual(Runner.prototype.someTask.mock, undefined);
375 t.mock.method(Runner, Runner.someTask.name);
376 assert.strictEqual(Runner.someTask.mock.calls.length, 0);
380 const call = Runner.someTask.mock.calls[0];
387 assert.strictEqual(Runner.someTask.mock.restore(), undefined);
389 assert.strictEqual(Runner.someTask.mock, undefined);
395 assert.throws(() => t.mock.method(null, {}), { code: 'ERR_INVALID_ARG_TYPE' });
399 assert.throws(() => t.mock.method({ abc: 0 }, 'non-existent'), {
420 t.mock.method(C, C.someTask.name);
421 assert.strictEqual(C.someTask.mock.calls.length, 0);
425 const call = C.someTask.mock.calls[0];
432 assert.strictEqual(C.someTask.mock.restore(), undefined);
434 assert.strictEqual(C.someTask.mock, undefined);
453 t.mock.method(C, C.someTask.name);
467 assert.strictEqual(C.someTask.mock.restore(), undefined);
474 const fn = t.mock.fn(() => {
479 assert.strictEqual(fn.mock.calls.length, 1);
481 const call = fn.mock.calls[0];
498 const ctor = t.mock.fn(Clazz);
503 assert.strictEqual(ctor.mock.calls.length, 1);
505 const call = ctor.mock.calls[0];
517 const fn = t.mock.fn(sum, difference);
519 assert.strictEqual(fn.mock.calls.length, 0);
522 assert.strictEqual(fn.mock.calls.length, 2);
524 let call = fn.mock.calls[0];
530 call = fn.mock.calls[1];
536 assert.strictEqual(fn.mock.restore(), undefined);
569 const ctor = t.mock.fn(Clazz, MockClazz);
578 assert.strictEqual(ctor.mock.calls.length, 1);
580 const call = ctor.mock.calls[0];
604 t.mock.method(obj, 'method', mockMethod);
605 assert.strictEqual(obj.method.mock.calls.length, 0);
608 const call = obj.method.mock.calls[0];
615 assert.strictEqual(obj.method.mock.restore(), undefined);
617 assert.strictEqual(obj.method.mock, undefined);
634 const getter = t.mock.method(obj, 'method', mockMethod, { getter: true });
636 assert.strictEqual(getter.mock.calls.length, 0);
639 const call = getter.mock.calls[0];
646 assert.strictEqual(getter.mock.restore(), undefined);
667 const setter = t.mock.method(obj, 'method', mockMethod, { setter: true });
669 assert.strictEqual(setter.mock.calls.length, 0);
672 assert.strictEqual(setter.mock.calls.length, 1);
674 const call = setter.mock.calls[0];
681 assert.strictEqual(setter.mock.restore(), undefined);
698 const getter = t.mock.getter(obj, 'method', mockMethod);
699 assert.strictEqual(getter.mock.calls.length, 0);
702 const call = getter.mock.calls[0];
709 assert.strictEqual(getter.mock.restore(), undefined);
730 const setter = t.mock.setter(obj, 'method', mockMethod);
732 assert.strictEqual(setter.mock.calls.length, 0);
735 assert.strictEqual(setter.mock.calls.length, 1);
737 const call = setter.mock.calls[0];
744 assert.strictEqual(setter.mock.restore(), undefined);
765 getNameAndLength(t.mock.fn(func1))
769 getNameAndLength(t.mock.fn(func2))
773 getNameAndLength(t.mock.fn(arrow))
777 getNameAndLength(t.mock.method(obj, 'method', func1))
798 t.mock.method(obj, 'method', mockMethod);
801 assert.strictEqual(obj.method.mock, undefined);
815 t.mock.method(obj, 'method', mockMethod);
818 assert.strictEqual(obj.method.mock, undefined);
834 const fn = t.mock.fn(addOne, addTwo, { times: 2 });
860 const fn = t.mock.fn(addOne);
862 assert.strictEqual(fn.mock.callCount(), 0);
866 assert.strictEqual(fn.mock.callCount(), 3);
868 fn.mock.mockImplementation(addTwo);
871 assert.strictEqual(fn.mock.callCount(), 5);
873 fn.mock.restore();
876 assert.strictEqual(fn.mock.callCount(), 7);
879 fn.mock.mockImplementationOnce(common.mustNotCall(), 6);
882 fn.mock.mockImplementationOnce(addThree, 7);
883 fn.mock.mockImplementationOnce(addTwo, 8);
887 assert.strictEqual(fn.mock.callCount(), 10);
888 fn.mock.mockImplementationOnce(addThree);
891 assert.strictEqual(fn.mock.callCount(), 12);
905 const mockFoo = t.mock.method(obj, 'foo');
922 const mockBar = t.mock.method(obj, 'bar');
936 const fn = t.mock.fn(sum, difference);
940 assert.strictEqual(fn.mock.calls.length, 2);
941 assert.strictEqual(fn.mock.callCount(), 2);
943 fn.mock.resetCalls();
944 assert.strictEqual(fn.mock.calls.length, 0);
945 assert.strictEqual(fn.mock.callCount(), 0);
959 const fn = mock.fn(sum, difference);
961 assert.strictEqual(fn.mock.calls.length, 0);
963 assert.strictEqual(fn.mock.calls.length, 1);
964 mock.reset();
966 assert.strictEqual(fn.mock.calls.length, 2);
971 t.mock.method({}, 'method', { getter: true, setter: true });
982 t.mock.method(obj, 'method');
983 t.mock.method(obj, symbol);
986 t.mock.method(obj, {});
992 t.mock.fn({ times: null });
996 t.mock.fn({ times: 0 });
1000 t.mock.fn(() => {}, { times: 3.14159 });
1018 t.mock.method(Clazz.prototype, 'getC');
1020 assert.strictEqual(instance.getC.mock.calls.length, 0);
1022 assert.strictEqual(instance.getC.mock.calls.length, 1);
1023 assert.strictEqual(Clazz.prototype.getC.mock.calls.length, 1);
1025 const call = instance.getC.mock.calls[0];
1035 t.mock.getter({}, 'method', { getter: false });
1041 t.mock.setter({}, 'method', { setter: false });
1047 t.mock.getter({}, 'method', { setter: true });
1053 t.mock.setter({}, 'method', { getter: true });