From 602bce34c8f7c2f8c68dd18f29243e467ed0fb08 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Sun, 9 Jan 2022 21:02:36 +0100 Subject: build: Add eslint-plugin-jest MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristóf Marussy --- .../__tests__/createSophieRenderer.spec.ts | 29 +++++++++++----------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts') diff --git a/packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts b/packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts index f63c3f6..b0af280 100644 --- a/packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts +++ b/packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts @@ -108,10 +108,10 @@ describe('SharedStoreConnector', () => { it('should request a snapshot from the main process', async () => { mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot); await sut.onSharedStoreChange(listener); - expect(ipcRenderer.invoke).toBeCalledWith( + expect(ipcRenderer.invoke).toHaveBeenCalledWith( RendererToMainIpcMessage.GetSharedStoreSnapshot, ); - expect(listener.onSnapshot).toBeCalledWith(snapshot); + expect(listener.onSnapshot).toHaveBeenCalledWith(snapshot); }); it('should catch IPC errors without exposing them', async () => { @@ -119,7 +119,7 @@ describe('SharedStoreConnector', () => { await expect( sut.onSharedStoreChange(listener), ).rejects.not.toHaveProperty('message', expect.stringMatching(/s3cr3t/)); - expect(listener.onSnapshot).not.toBeCalled(); + expect(listener.onSnapshot).not.toHaveBeenCalled(); }); it('should not pass on invalid snapshots', async () => { @@ -127,28 +127,28 @@ describe('SharedStoreConnector', () => { await expect(sut.onSharedStoreChange(listener)).rejects.toBeInstanceOf( Error, ); - expect(listener.onSnapshot).not.toBeCalled(); + expect(listener.onSnapshot).not.toHaveBeenCalled(); }); }); describe('dispatchAction', () => { it('should dispatch valid actions', () => { sut.dispatchAction(action); - expect(ipcRenderer.send).toBeCalledWith( + expect(ipcRenderer.send).toHaveBeenCalledWith( RendererToMainIpcMessage.DispatchAction, action, ); }); it('should not dispatch invalid actions', () => { - expect(() => sut.dispatchAction(invalidAction)).toThrowError(); - expect(ipcRenderer.send).not.toBeCalled(); + expect(() => sut.dispatchAction(invalidAction)).toThrow(); + expect(ipcRenderer.send).not.toHaveBeenCalled(); }); }); describe('when no listener is registered', () => { it('should discard the received patch without any error', () => { - onSharedStorePatch(event, patch); + expect(() => onSharedStorePatch(event, patch)).not.toThrow(); }); }); @@ -163,9 +163,10 @@ describe('SharedStoreConnector', () => { function itDoesNotPassPatchesToTheListener( name = 'should not pass patches to the listener', ): void { + // eslint-disable-next-line jest/valid-title -- Title is a string parameter. it(name, () => { onSharedStorePatch(event, patch); - expect(listener.onPatch).not.toBeCalled(); + expect(listener.onPatch).not.toHaveBeenCalled(); }); } @@ -177,14 +178,14 @@ describe('SharedStoreConnector', () => { it('should pass patches to the listener', () => { onSharedStorePatch(event, patch); - expect(listener.onPatch).toBeCalledWith(patch); + expect(listener.onPatch).toHaveBeenCalledWith(patch); }); it('should catch listener errors', () => { mocked(listener.onPatch).mockImplementation(() => { throw new Error(); }); - onSharedStorePatch(event, patch); + expect(() => onSharedStorePatch(event, patch)).not.toThrow(); }); itRefusesToRegisterAnotherListener(); @@ -264,17 +265,17 @@ describe('SharedStoreConnector', () => { it('should fetch a second snapshot', async () => { mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); await sut.onSharedStoreChange(listener2); - expect(ipcRenderer.invoke).toBeCalledWith( + expect(ipcRenderer.invoke).toHaveBeenCalledWith( RendererToMainIpcMessage.GetSharedStoreSnapshot, ); - expect(listener2.onSnapshot).toBeCalledWith(snapshot2); + expect(listener2.onSnapshot).toHaveBeenCalledWith(snapshot2); }); it('should pass the second snapshot to the new listener', async () => { mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); await sut.onSharedStoreChange(listener2); onSharedStorePatch(event, patch); - expect(listener2.onPatch).toBeCalledWith(patch); + expect(listener2.onPatch).toHaveBeenCalledWith(patch); }); }); }); -- cgit v1.2.3-70-g09d2