diff options
Diffstat (limited to 'packages/preload')
-rw-r--r-- | packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts | 29 |
1 files changed, 15 insertions, 14 deletions
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', () => { | |||
108 | it('should request a snapshot from the main process', async () => { | 108 | it('should request a snapshot from the main process', async () => { |
109 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot); | 109 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot); |
110 | await sut.onSharedStoreChange(listener); | 110 | await sut.onSharedStoreChange(listener); |
111 | expect(ipcRenderer.invoke).toBeCalledWith( | 111 | expect(ipcRenderer.invoke).toHaveBeenCalledWith( |
112 | RendererToMainIpcMessage.GetSharedStoreSnapshot, | 112 | RendererToMainIpcMessage.GetSharedStoreSnapshot, |
113 | ); | 113 | ); |
114 | expect(listener.onSnapshot).toBeCalledWith(snapshot); | 114 | expect(listener.onSnapshot).toHaveBeenCalledWith(snapshot); |
115 | }); | 115 | }); |
116 | 116 | ||
117 | it('should catch IPC errors without exposing them', async () => { | 117 | it('should catch IPC errors without exposing them', async () => { |
@@ -119,7 +119,7 @@ describe('SharedStoreConnector', () => { | |||
119 | await expect( | 119 | await expect( |
120 | sut.onSharedStoreChange(listener), | 120 | sut.onSharedStoreChange(listener), |
121 | ).rejects.not.toHaveProperty('message', expect.stringMatching(/s3cr3t/)); | 121 | ).rejects.not.toHaveProperty('message', expect.stringMatching(/s3cr3t/)); |
122 | expect(listener.onSnapshot).not.toBeCalled(); | 122 | expect(listener.onSnapshot).not.toHaveBeenCalled(); |
123 | }); | 123 | }); |
124 | 124 | ||
125 | it('should not pass on invalid snapshots', async () => { | 125 | it('should not pass on invalid snapshots', async () => { |
@@ -127,28 +127,28 @@ describe('SharedStoreConnector', () => { | |||
127 | await expect(sut.onSharedStoreChange(listener)).rejects.toBeInstanceOf( | 127 | await expect(sut.onSharedStoreChange(listener)).rejects.toBeInstanceOf( |
128 | Error, | 128 | Error, |
129 | ); | 129 | ); |
130 | expect(listener.onSnapshot).not.toBeCalled(); | 130 | expect(listener.onSnapshot).not.toHaveBeenCalled(); |
131 | }); | 131 | }); |
132 | }); | 132 | }); |
133 | 133 | ||
134 | describe('dispatchAction', () => { | 134 | describe('dispatchAction', () => { |
135 | it('should dispatch valid actions', () => { | 135 | it('should dispatch valid actions', () => { |
136 | sut.dispatchAction(action); | 136 | sut.dispatchAction(action); |
137 | expect(ipcRenderer.send).toBeCalledWith( | 137 | expect(ipcRenderer.send).toHaveBeenCalledWith( |
138 | RendererToMainIpcMessage.DispatchAction, | 138 | RendererToMainIpcMessage.DispatchAction, |
139 | action, | 139 | action, |
140 | ); | 140 | ); |
141 | }); | 141 | }); |
142 | 142 | ||
143 | it('should not dispatch invalid actions', () => { | 143 | it('should not dispatch invalid actions', () => { |
144 | expect(() => sut.dispatchAction(invalidAction)).toThrowError(); | 144 | expect(() => sut.dispatchAction(invalidAction)).toThrow(); |
145 | expect(ipcRenderer.send).not.toBeCalled(); | 145 | expect(ipcRenderer.send).not.toHaveBeenCalled(); |
146 | }); | 146 | }); |
147 | }); | 147 | }); |
148 | 148 | ||
149 | describe('when no listener is registered', () => { | 149 | describe('when no listener is registered', () => { |
150 | it('should discard the received patch without any error', () => { | 150 | it('should discard the received patch without any error', () => { |
151 | onSharedStorePatch(event, patch); | 151 | expect(() => onSharedStorePatch(event, patch)).not.toThrow(); |
152 | }); | 152 | }); |
153 | }); | 153 | }); |
154 | 154 | ||
@@ -163,9 +163,10 @@ describe('SharedStoreConnector', () => { | |||
163 | function itDoesNotPassPatchesToTheListener( | 163 | function itDoesNotPassPatchesToTheListener( |
164 | name = 'should not pass patches to the listener', | 164 | name = 'should not pass patches to the listener', |
165 | ): void { | 165 | ): void { |
166 | // eslint-disable-next-line jest/valid-title -- Title is a string parameter. | ||
166 | it(name, () => { | 167 | it(name, () => { |
167 | onSharedStorePatch(event, patch); | 168 | onSharedStorePatch(event, patch); |
168 | expect(listener.onPatch).not.toBeCalled(); | 169 | expect(listener.onPatch).not.toHaveBeenCalled(); |
169 | }); | 170 | }); |
170 | } | 171 | } |
171 | 172 | ||
@@ -177,14 +178,14 @@ describe('SharedStoreConnector', () => { | |||
177 | 178 | ||
178 | it('should pass patches to the listener', () => { | 179 | it('should pass patches to the listener', () => { |
179 | onSharedStorePatch(event, patch); | 180 | onSharedStorePatch(event, patch); |
180 | expect(listener.onPatch).toBeCalledWith(patch); | 181 | expect(listener.onPatch).toHaveBeenCalledWith(patch); |
181 | }); | 182 | }); |
182 | 183 | ||
183 | it('should catch listener errors', () => { | 184 | it('should catch listener errors', () => { |
184 | mocked(listener.onPatch).mockImplementation(() => { | 185 | mocked(listener.onPatch).mockImplementation(() => { |
185 | throw new Error(); | 186 | throw new Error(); |
186 | }); | 187 | }); |
187 | onSharedStorePatch(event, patch); | 188 | expect(() => onSharedStorePatch(event, patch)).not.toThrow(); |
188 | }); | 189 | }); |
189 | 190 | ||
190 | itRefusesToRegisterAnotherListener(); | 191 | itRefusesToRegisterAnotherListener(); |
@@ -264,17 +265,17 @@ describe('SharedStoreConnector', () => { | |||
264 | it('should fetch a second snapshot', async () => { | 265 | it('should fetch a second snapshot', async () => { |
265 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); | 266 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); |
266 | await sut.onSharedStoreChange(listener2); | 267 | await sut.onSharedStoreChange(listener2); |
267 | expect(ipcRenderer.invoke).toBeCalledWith( | 268 | expect(ipcRenderer.invoke).toHaveBeenCalledWith( |
268 | RendererToMainIpcMessage.GetSharedStoreSnapshot, | 269 | RendererToMainIpcMessage.GetSharedStoreSnapshot, |
269 | ); | 270 | ); |
270 | expect(listener2.onSnapshot).toBeCalledWith(snapshot2); | 271 | expect(listener2.onSnapshot).toHaveBeenCalledWith(snapshot2); |
271 | }); | 272 | }); |
272 | 273 | ||
273 | it('should pass the second snapshot to the new listener', async () => { | 274 | it('should pass the second snapshot to the new listener', async () => { |
274 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); | 275 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); |
275 | await sut.onSharedStoreChange(listener2); | 276 | await sut.onSharedStoreChange(listener2); |
276 | onSharedStorePatch(event, patch); | 277 | onSharedStorePatch(event, patch); |
277 | expect(listener2.onPatch).toBeCalledWith(patch); | 278 | expect(listener2.onPatch).toHaveBeenCalledWith(patch); |
278 | }); | 279 | }); |
279 | }); | 280 | }); |
280 | }); | 281 | }); |