describe( 'isMobile', () => { test( 'should retrieve the current status for the mobile breakpoint', () => { expect( viewport.isMobile() ).toBe( 'foo' ); expect( matchesMock ).toHaveBeenCalledTimes( 1 ); expect( matchesMock ).toHaveBeenCalledWith( '(max-width: 480px)' ); } ); } );
test('performs action when calling perform on turn', () => { const walk = { perform: jest.fn() }; unit.addAbility('walk', walk); unit.turn = { action: ['walk', ['backward']] }; unit.performTurn(); expect(walk.perform).toHaveBeenCalledWith('backward'); });
it('should not succeed if the socket.remoteAddress does not belong to masterKeyIps list', () => { AppCache.put(fakeReq.body._ApplicationId, { masterKey: 'masterKey', masterKeyIps: ['ip1', 'ip2'], }); fakeReq.socket = { remoteAddress: 'ip3' }; fakeReq.headers['x-parse-master-key'] = 'masterKey'; middlewares.handleParseHeaders(fakeReq, fakeRes); expect(fakeRes.status).toHaveBeenCalledWith(403); });
test('prints log message with dimmed gray prompt', () => { const unitStyle = jest.fn(string => string); getUnitStyle.mockReturnValue(unitStyle); const unit = { name: 'Joe' }; const prompt = `${style.gray.open}${style.dim.open}>${style.dim.close}${ style.gray.close }`; printLogMessage(unit, 'is awesome!'); expect(getUnitStyle).toHaveBeenCalledWith(unit); expect(unitStyle).toHaveBeenCalledWith('Joe is awesome!'); expect(printLine).toHaveBeenCalledWith(`${prompt} Joe is awesome!`); });
test('prints message and fills with padding', () => { getScreenSize.mockReturnValue([11, 0]); printRow('foo', { position: 'start', padding: ' ' }); expect(printLine).toHaveBeenCalledWith('foo '); });
it('auto-escapes symbols in auth information', () => { spyOn(MongoClient, 'connect').and.returnValue(Promise.resolve(fakeClient)); new MongoStorageAdapter({ uri: 'mongodb://user!with@+ symbols:password!with@+ symbols@localhost:1234/parse', }).connect(); expect(MongoClient.connect).toHaveBeenCalledWith( 'mongodb://user!with%40%2B%20symbols:password!with%40%2B%20symbols@localhost:1234/parse', jasmine.any(Object) ); });
test('default option defaults to false', async () => { await requestConfirmation('foo'); expect(inquirer.prompt).toHaveBeenCalledWith([ { name: 'requestConfirmation', type: 'confirm', message: 'foo', default: false, }, ]); });
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'], ); });
test('returns zero if the level is not clear', () => { getLastEvent.mockReturnValue({ floorMap: 'map' }); isFloorClear.mockReturnValue(false); expect(getClearBonus('events', 3, 2)).toBe(0); expect(getLastEvent).toHaveBeenCalledWith('events'); expect(isFloorClear).toHaveBeenCalledWith('map'); });
test('prints warrior status and floor map', () => { const floorMap = ['row1', 'row2']; const warriorStatus = 'status'; printBoard(floorMap, warriorStatus); expect(print).not.toHaveBeenCalled(); expect(printWarriorStatus).toHaveBeenCalledWith(warriorStatus); expect(printFloorMap).toHaveBeenCalledWith(floorMap); });
test('starts the game', async () => { const mockStart = jest.fn(); Game.mockImplementation(() => ({ start: mockStart })); await run(['-d', '/path/to/game', '-l', '2', '-s', '-t', '0.3', '-y']); expect(Game).toHaveBeenCalledWith('/path/to/game', 2, true, 0.3, true); expect(mockStart).toHaveBeenCalled(); });
test("doesn't go below zero", () => { getTurnCount.mockReturnValue(11); expect(getRemainingTimeBonus('events', 10)).toBe(0); expect(getTurnCount).toHaveBeenCalledWith('events'); });
test('sleeps the specified time at the beginning and after each event', async () => { const events = [ [{ unit: 'foo', message: 'bar' }, { unit: 'foo', message: 'bar' }], [{ unit: 'foo', message: 'bar' }], [{ unit: 'foo', message: 'bar' }], ]; await printPlay(events, 42); expect(delay).toHaveBeenCalledTimes(5); expect(delay).toHaveBeenCalledWith(42); });
test('prints board on each event', async () => { const events = [ [{ floorMap: 'floor1', warriorStatus: 'status1' }], [{ floorMap: 'floor2', warriorStatus: 'status2' }], ]; await printPlay(events); expect(printBoard).toHaveBeenCalledWith('floor1', 'status1', 0); expect(printBoard).toHaveBeenCalledWith('floor2', 'status2', 0); });
test('positions message at the end if specified', () => { getScreenSize.mockReturnValue([11, 0]); printRow('foo', { position: 'end' }); expect(printLine).toHaveBeenCalledWith(' foo'); });