FrontendAtlas
Study
▾
Dashboard
Pricing
Get full access
</> Code
Test cases
Language
JavaScript
TypeScript
export default function createSpy(impl) { throw new Error('Not implemented'); }
import createSpy from './createSpy'; describe('createSpy', () => { test('records calls and arguments', () => { const spy = createSpy(); spy(1, 2); spy('a'); expect(spy.callCount()).toBe(2); expect(spy.calls).toEqual([[1, 2], ['a']]); expect(spy.lastCall()).toEqual(['a']); }); test('delegates to the implementation and returns its value', () => { const spy = createSpy((a, b) => a + b); const out = spy(2, 3); expect(out).toBe(5); expect(spy.calls[0]).toEqual([2, 3]); }); test('preserves this binding when used as a method', () => { const obj = { x: 10, fn: createSpy(function (n) { return this.x + n; }) }; const out = obj.fn(2); expect(out).toBe(12); expect(obj.fn.thisValues[0]).toBe(obj); }); test('reset clears recorded calls', () => { const spy = createSpy(); spy(1); spy.reset(); expect(spy.callCount()).toBe(0); expect(spy.calls).toEqual([]); expect(spy.lastCall()).toBe(null); }); });
▶ Run tests
Results
Console
Run tests to see results.