jest.mock( 'lib/wp', () => ( { undocumented: () => ( { getProducts: () => {}, } ), } ) );
test('starts counting board offset from zero, increments on each event and resets on each new turn', async () => { const events = [ [{ unit: 'foo', message: 'bar' }, { unit: 'foo', message: 'bar' }], [{ unit: 'foo', message: 'bar' }], [{ unit: 'foo', message: 'bar' }], ]; await printPlay(events); expect(printBoard.mock.calls[0][2]).toBe(0); expect(printBoard.mock.calls[1][2]).toBe(1); expect(printBoard.mock.calls[2][2]).toBe(0); expect(printBoard.mock.calls[3][2]).toBe(0); });
test('makes directory', () => { mock({ '/path/to': {} }); profile.makeProfileDirectory(); expect(fs.statSync('/path/to/profile').isDirectory()).toBe(true); mock.restore(); });
it("should throw error if packet is too large", () => { let cb = jest.fn(); let buf = Buffer.alloc(513, "0"); parser._write(buf, null, cb); expect(cb).toHaveBeenCalledTimes(1); expect(cb).toHaveBeenCalledWith(jasmine.any(Error)); let err = cb.mock.calls[0][0]; expect(err.message).toBe("Incoming packet is larger than the 'maxPacketSize' limit (513 > 512)!"); expect(parser.buf).toBeNull(); });
it('should commit offsets while running', async () => { await runner.commitOffsets(offsets) expect(consumerGroup.commitOffsetsIfNecessary).toHaveBeenCalledTimes(0) expect(consumerGroup.commitOffsets.mock.calls.length).toBeGreaterThanOrEqual(1) expect(consumerGroup.commitOffsets).toHaveBeenCalledWith(offsets) })
test('loads internal towers', () => { mock({ '/path/to/node_modules/@warriorjs/cli': {} }); loadTowers(); mock.restore(); expect(Tower).toHaveBeenCalledWith( 'baby-steps', 'Baby Steps', 'For players new to WarriorJS', ['level1', 'level2'], ); });
// const lolex = require("@sinonjs/fake-timers"); jest.mock("../../../../src/transporters/tcp/parser", () => { return jest.fn().mockImplementation(() => { let callbacks = {}; let parser = { on: jest.fn((type, cb) => callbacks[type] = cb), __callbacks: callbacks }; return parser; }); });
// Mock out this component until @wordpress/block-editor // `BlockPreview` component is available as default export. // Once available, swap this mock to mocking out `BlockPreview` // directly as it causes too many knock on effects when rendering jest.mock( '../block-iframe-preview', () => () => { return <div data-testid="block-template-preview">MockedBlockPreview</div>; } );
jest.mock( 'lib/wp', () => { const readFeedPost = jest.fn(); const readSitePost = jest.fn(); return { undocumented: () => ( { readFeedPost, readSitePost, } ), }; } );
jest.mock('../retry', () => { const spy = jest.fn().mockImplementation(jest.requireActual('../retry')) retrySpy = spy return spy })
jest.mock('chrome-launcher', () => { return { launch() { return { port: '1234', kill() { return null } } } } })
// Mock necessary for testing certain utils jest.mock( 'signup/config/flows-pure', () => ( { 'new-flow': { steps: [ 'something', 'everything' ], }, } ) );
// Mock necessary for testing step submission behavior jest.mock( 'signup/config/steps-pure', () => ( { stepWithAPI: { apiRequestFunction: () => {} }, stepWithoutAPI: {}, } ) );
jest.mock( 'lib/user', () => () => { return { get() { return {}; }, }; } );
test('starts counting board offset from zero, increments on each event and resets on each new turn', async () => { const events = [ [{ unit: 'foo', message: 'bar' }, { unit: 'foo', message: 'bar' }], [{ unit: 'foo', message: 'bar' }], [{ unit: 'foo', message: 'bar' }], ]; await printPlay(events); expect(printBoard.mock.calls[0][2]).toBe(0); expect(printBoard.mock.calls[1][2]).toBe(1); expect(printBoard.mock.calls[2][2]).toBe(0); expect(printBoard.mock.calls[3][2]).toBe(0); });