-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: prevent auto-cleanup to throw when asserting errors in async lif…
…ecycle hooks (#142) * fix: delete wrappers before destroying `wrapper.destroy()` will rethrow any errors via vue test utils `throwIfInstancesThrew`. ensure that wrappers are deleted from mountedWrappers at any time * test: add tests for re-throwing async lifecycle hooks * Update src/__tests__/cleanup-throw.js Co-authored-by: Adrià Fontcuberta <[email protected]>
- Loading branch information
1 parent
b54744a
commit 4c5f724
Showing
2 changed files
with
26 additions
and
3 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,21 @@ | ||
import {render, cleanup} from '@testing-library/vue' | ||
import Vue from 'vue' | ||
|
||
test('cleanup re-throws errors from async lifecycle hooks', async () => { | ||
const err = new Error('foo') | ||
render({ | ||
async mounted() { | ||
await new Promise((resolve, reject) => reject(err)) | ||
}, | ||
template: `<h1>Hello World</h1>`, | ||
}) | ||
// thrown errors are logged redundantly by vue-test-utils injected Vue.config.errorHandler | ||
// mute console | ||
const spy = jest.spyOn(console, 'error').mockImplementation(() => {}) | ||
|
||
await Vue.nextTick() | ||
expect(cleanup).toThrow(err) | ||
|
||
// unmute console | ||
spy.mockReset() | ||
}) |
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