diff options
author | 2022-05-09 01:37:06 +0200 | |
---|---|---|
committer | 2022-05-16 00:55:03 +0200 | |
commit | a6fade92974dbba63a7d7a07f80bb447dfdf4f5b (patch) | |
tree | 8c7dfc3cc4a041412cc6be9a260acc8238b78013 /packages/preload/src/contextBridge/__tests__ | |
parent | test: prefer jest API instead of jest-each (diff) | |
download | sophie-a6fade92974dbba63a7d7a07f80bb447dfdf4f5b.tar.gz sophie-a6fade92974dbba63a7d7a07f80bb447dfdf4f5b.tar.zst sophie-a6fade92974dbba63a7d7a07f80bb447dfdf4f5b.zip |
test: use test instead of it
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/preload/src/contextBridge/__tests__')
-rw-r--r-- | packages/preload/src/contextBridge/__tests__/createSophieRenderer.test.ts (renamed from packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts) | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts b/packages/preload/src/contextBridge/__tests__/createSophieRenderer.test.ts index 4411789..21620ed 100644 --- a/packages/preload/src/contextBridge/__tests__/createSophieRenderer.spec.ts +++ b/packages/preload/src/contextBridge/__tests__/createSophieRenderer.test.ts | |||
@@ -73,7 +73,7 @@ beforeAll(() => { | |||
73 | }); | 73 | }); |
74 | 74 | ||
75 | describe('createSophieRenderer', () => { | 75 | describe('createSophieRenderer', () => { |
76 | it('registers a shared store patch listener', () => { | 76 | test('registers a shared store patch listener', () => { |
77 | createSophieRenderer(false); | 77 | createSophieRenderer(false); |
78 | expect(ipcRenderer.on).toHaveBeenCalledWith( | 78 | expect(ipcRenderer.on).toHaveBeenCalledWith( |
79 | MainToRendererIpcMessage.SharedStorePatch, | 79 | MainToRendererIpcMessage.SharedStorePatch, |
@@ -103,7 +103,7 @@ describe('SharedStoreConnector', () => { | |||
103 | }); | 103 | }); |
104 | 104 | ||
105 | describe('onSharedStoreChange', () => { | 105 | describe('onSharedStoreChange', () => { |
106 | it('should request a snapshot from the main process', async () => { | 106 | test('requests a snapshot from the main process', async () => { |
107 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot); | 107 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot); |
108 | await sut.onSharedStoreChange(listener); | 108 | await sut.onSharedStoreChange(listener); |
109 | expect(ipcRenderer.invoke).toHaveBeenCalledWith( | 109 | expect(ipcRenderer.invoke).toHaveBeenCalledWith( |
@@ -112,7 +112,7 @@ describe('SharedStoreConnector', () => { | |||
112 | expect(listener.onSnapshot).toHaveBeenCalledWith(snapshot); | 112 | expect(listener.onSnapshot).toHaveBeenCalledWith(snapshot); |
113 | }); | 113 | }); |
114 | 114 | ||
115 | it('should catch IPC errors without exposing them', async () => { | 115 | test('catches IPC errors without exposing them', async () => { |
116 | mocked(ipcRenderer.invoke).mockRejectedValue(new Error('s3cr3t')); | 116 | mocked(ipcRenderer.invoke).mockRejectedValue(new Error('s3cr3t')); |
117 | await expect( | 117 | await expect( |
118 | sut.onSharedStoreChange(listener), | 118 | sut.onSharedStoreChange(listener), |
@@ -122,7 +122,7 @@ describe('SharedStoreConnector', () => { | |||
122 | }); | 122 | }); |
123 | 123 | ||
124 | describe('dispatchAction', () => { | 124 | describe('dispatchAction', () => { |
125 | it('should dispatch valid actions', () => { | 125 | test('dispatches valid actions', () => { |
126 | sut.dispatchAction(action); | 126 | sut.dispatchAction(action); |
127 | expect(ipcRenderer.send).toHaveBeenCalledWith( | 127 | expect(ipcRenderer.send).toHaveBeenCalledWith( |
128 | RendererToMainIpcMessage.DispatchAction, | 128 | RendererToMainIpcMessage.DispatchAction, |
@@ -130,31 +130,31 @@ describe('SharedStoreConnector', () => { | |||
130 | ); | 130 | ); |
131 | }); | 131 | }); |
132 | 132 | ||
133 | it('should not dispatch invalid actions', () => { | 133 | test('does not dispatch invalid actions', () => { |
134 | expect(() => sut.dispatchAction(invalidAction)).toThrow(); | 134 | expect(() => sut.dispatchAction(invalidAction)).toThrow(); |
135 | expect(ipcRenderer.send).not.toHaveBeenCalled(); | 135 | expect(ipcRenderer.send).not.toHaveBeenCalled(); |
136 | }); | 136 | }); |
137 | }); | 137 | }); |
138 | 138 | ||
139 | describe('when no listener is registered', () => { | 139 | describe('when no listener is registered', () => { |
140 | it('should discard the received patch without any error', () => { | 140 | test('discards the received patch without any error', () => { |
141 | expect(() => onSharedStorePatch(event, patch)).not.toThrow(); | 141 | expect(() => onSharedStorePatch(event, patch)).not.toThrow(); |
142 | }); | 142 | }); |
143 | }); | 143 | }); |
144 | 144 | ||
145 | function itRefusesToRegisterAnotherListener(): void { | 145 | function testRefusesToRegisterAnotherListener(): void { |
146 | it('should refuse to register another listener', async () => { | 146 | test('refuses to register another listener', async () => { |
147 | await expect(sut.onSharedStoreChange(listener)).rejects.toBeInstanceOf( | 147 | await expect(sut.onSharedStoreChange(listener)).rejects.toBeInstanceOf( |
148 | Error, | 148 | Error, |
149 | ); | 149 | ); |
150 | }); | 150 | }); |
151 | } | 151 | } |
152 | 152 | ||
153 | function itDoesNotPassPatchesToTheListener( | 153 | function testDoesNotPassPatchesToTheListener( |
154 | name = 'should not pass patches to the listener', | 154 | name = 'does not pass patches to the listener', |
155 | ): void { | 155 | ): void { |
156 | // eslint-disable-next-line jest/valid-title -- Title is a string parameter. | 156 | // eslint-disable-next-line jest/valid-title -- Title is a string parameter. |
157 | it(name, () => { | 157 | test(name, () => { |
158 | onSharedStorePatch(event, patch); | 158 | onSharedStorePatch(event, patch); |
159 | expect(listener.onPatch).not.toHaveBeenCalled(); | 159 | expect(listener.onPatch).not.toHaveBeenCalled(); |
160 | }); | 160 | }); |
@@ -166,19 +166,19 @@ describe('SharedStoreConnector', () => { | |||
166 | await sut.onSharedStoreChange(listener); | 166 | await sut.onSharedStoreChange(listener); |
167 | }); | 167 | }); |
168 | 168 | ||
169 | it('should pass patches to the listener', () => { | 169 | test('passes patches to the listener', () => { |
170 | onSharedStorePatch(event, patch); | 170 | onSharedStorePatch(event, patch); |
171 | expect(listener.onPatch).toHaveBeenCalledWith(patch); | 171 | expect(listener.onPatch).toHaveBeenCalledWith(patch); |
172 | }); | 172 | }); |
173 | 173 | ||
174 | it('should catch listener errors', () => { | 174 | test('catches listener errors', () => { |
175 | mocked(listener.onPatch).mockImplementation(() => { | 175 | mocked(listener.onPatch).mockImplementation(() => { |
176 | throw new Error('listener error'); | 176 | throw new Error('listener error'); |
177 | }); | 177 | }); |
178 | expect(() => onSharedStorePatch(event, patch)).not.toThrow(); | 178 | expect(() => onSharedStorePatch(event, patch)).not.toThrow(); |
179 | }); | 179 | }); |
180 | 180 | ||
181 | itRefusesToRegisterAnotherListener(); | 181 | testRefusesToRegisterAnotherListener(); |
182 | 182 | ||
183 | describe('after the listener threw in onPatch', () => { | 183 | describe('after the listener threw in onPatch', () => { |
184 | beforeEach(() => { | 184 | beforeEach(() => { |
@@ -189,7 +189,7 @@ describe('SharedStoreConnector', () => { | |||
189 | listener.onPatch.mockRestore(); | 189 | listener.onPatch.mockRestore(); |
190 | }); | 190 | }); |
191 | 191 | ||
192 | itDoesNotPassPatchesToTheListener('should not pass on patches any more'); | 192 | testDoesNotPassPatchesToTheListener('does not pass on patches any more'); |
193 | }); | 193 | }); |
194 | }); | 194 | }); |
195 | 195 | ||
@@ -205,9 +205,9 @@ describe('SharedStoreConnector', () => { | |||
205 | } | 205 | } |
206 | }); | 206 | }); |
207 | 207 | ||
208 | itRefusesToRegisterAnotherListener(); | 208 | testRefusesToRegisterAnotherListener(); |
209 | 209 | ||
210 | itDoesNotPassPatchesToTheListener(); | 210 | testDoesNotPassPatchesToTheListener(); |
211 | }); | 211 | }); |
212 | 212 | ||
213 | describe('when a listener failed to register due to listener error', () => { | 213 | describe('when a listener failed to register due to listener error', () => { |
@@ -223,9 +223,9 @@ describe('SharedStoreConnector', () => { | |||
223 | } | 223 | } |
224 | }); | 224 | }); |
225 | 225 | ||
226 | itRefusesToRegisterAnotherListener(); | 226 | testRefusesToRegisterAnotherListener(); |
227 | 227 | ||
228 | itDoesNotPassPatchesToTheListener(); | 228 | testDoesNotPassPatchesToTheListener(); |
229 | }); | 229 | }); |
230 | 230 | ||
231 | describe('when it is allowed to replace listeners', () => { | 231 | describe('when it is allowed to replace listeners', () => { |
@@ -239,7 +239,7 @@ describe('SharedStoreConnector', () => { | |||
239 | onPatch: jest.fn((_patch: IJsonPatch[]) => {}), | 239 | onPatch: jest.fn((_patch: IJsonPatch[]) => {}), |
240 | }; | 240 | }; |
241 | 241 | ||
242 | it('should fetch a second snapshot', async () => { | 242 | test('fetches a second snapshot', async () => { |
243 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); | 243 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); |
244 | await sut.onSharedStoreChange(listener2); | 244 | await sut.onSharedStoreChange(listener2); |
245 | expect(ipcRenderer.invoke).toHaveBeenCalledWith( | 245 | expect(ipcRenderer.invoke).toHaveBeenCalledWith( |
@@ -248,7 +248,7 @@ describe('SharedStoreConnector', () => { | |||
248 | expect(listener2.onSnapshot).toHaveBeenCalledWith(snapshot2); | 248 | expect(listener2.onSnapshot).toHaveBeenCalledWith(snapshot2); |
249 | }); | 249 | }); |
250 | 250 | ||
251 | it('should pass the second snapshot to the new listener', async () => { | 251 | test('passes the second snapshot to the new listener', async () => { |
252 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); | 252 | mocked(ipcRenderer.invoke).mockResolvedValueOnce(snapshot2); |
253 | await sut.onSharedStoreChange(listener2); | 253 | await sut.onSharedStoreChange(listener2); |
254 | onSharedStorePatch(event, patch); | 254 | onSharedStorePatch(event, patch); |