-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: cleaner recordHook error messages (#327)
* feat: cleaner recordHook error messages * Create few-yaks-fetch.md * feat: add test for error message * add reset script * feat: restructure test & console.log -> console.error
- Loading branch information
1 parent
7835dcc
commit f18a889
Showing
4 changed files
with
41 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@flatfile/plugin-record-hook': patch | ||
--- | ||
|
||
Human-readable errors from recordHook |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,4 +67,31 @@ describe('recordHook() e2e', () => { | |
expect(records[1].values['name']).toMatchObject({ value: 'daddy' }) | ||
}) | ||
}) | ||
|
||
describe('recordHook errors', () => { | ||
const logErrorSpy = jest.spyOn(global.console, 'error') | ||
beforeEach(async () => { | ||
listener.use( | ||
recordHook('test', (record) => { | ||
throw new Error('oops') | ||
}) | ||
) | ||
await createRecords(sheetId, [ | ||
{ | ||
name: 'John Doe', | ||
email: '[email protected]', | ||
notes: 'foobar', | ||
}, | ||
]) | ||
}) | ||
it('returns readable error', async () => { | ||
await listener.waitFor('commit:created') | ||
expect(logErrorSpy).toHaveBeenCalledWith( | ||
'An error occurred while running the handler: oops' | ||
) | ||
}) | ||
afterEach(() => { | ||
logErrorSpy.mockClear() | ||
}) | ||
}) | ||
}) |