Category : unit-testing

I would like to test this with Jest const accept = () => new Promise<boolean>(resolve => { const acceptBtn = document.getElementById(‘accept’); acceptBtn.onclick => () => resolve(true); }) test(‘should return true’, async() => { const spyDocument = jest.spyOn(document, ‘getElementById’); const btn = document.createElement(‘button’); img.id = ‘accept’; img.click = jest.fn(() => Promise.resolve(true)); spyDocument.mockReturnValue(img); const accepted = await ..

Read more

I have a test where I define a player object in the beforeEach. In my test, after each jest.advanceTimersByTime(2001) call, player.seekable.mock.calls increments so since I call jest.advanceTimersByTime(2001) two times, the player.seekable.mock.calls.length is 2. initPlayer.test.js describe(‘testing’, () => { let player, seekableEnd; beforeEach(() => { seekableEnd = 120; player = { currentTime: jest.fn(), seekable: jest.fn(() => ..

Read more

I had a test file that defines a player object at the top. file.test.js let player; player = { qualityLevels: jest.fn(() => { return { selectedIndex: 0, 0: qualityLevel, on: qualityListener, }; }), seekable: jest.fn(() => { return { end: jest.fn().mockReturnValue(seekableEnd), }; }), } videojs.mockReturnValue(player); I moved that into a helper file called player.js player.js ..

Read more