Skip to content

Commit

Permalink
test(nest-electron): throw error
Browse files Browse the repository at this point in the history
  • Loading branch information
ArcherGu committed Feb 8, 2023
1 parent 4c607c6 commit f11b101
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 1 deletion.
4 changes: 4 additions & 0 deletions packages/nest-electron/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,8 @@ describe('Doubleshot Nest Electron Module', () => {
it('should also support call functions with decorators directly', async () => {
expect(logs).toContain('Get log: Direct call function')
})

it('should throw an error if an error occurs in the main process', async () => {
expect(logs).toContain('This is an error')
})
})
9 changes: 8 additions & 1 deletion packages/nest-electron/test/mock/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,17 @@ <h1>Doubleshot Nest Electron Module Test</h1>
chat,
printLog,
sendMultiParams,
throwError,
exit
} = window.electron

const test = async () => {
try {
await throwError()
} catch (error) {
await printLog(error.message)
}

const msgFromBackend = await chat('This is a message to backend')

await printLog(msgFromBackend)
Expand All @@ -33,4 +40,4 @@ <h1>Doubleshot Nest Electron Module Test</h1>
</script>
</body>

</html>
</html>
5 changes: 5 additions & 0 deletions packages/nest-electron/test/mock/src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ export class AppController {
return 'This is a message to frontend'
}

@IpcHandle('error')
throwError() {
throw new Error('This is an error')
}

@IpcOn('print-log')
printLog(log: string) {
console.log(`Get log: ${log}`)
Expand Down
1 change: 1 addition & 0 deletions packages/nest-electron/test/mock/src/preload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ contextBridge.exposeInMainWorld(
'electron',
{
chat: (msg: string): Promise<string> => ipcRenderer.invoke('chat', msg),
throwError: (): Promise<void> => ipcRenderer.invoke('error'),
printLog: (log: string): void => ipcRenderer.send('print-log', log),
sendMultiParams: (param1: string, param2: string): void => ipcRenderer.send('multi-params', param1, param2),
exit: (): void => ipcRenderer.send('exit'),
Expand Down

0 comments on commit f11b101

Please sign in to comment.