-
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.
feat(cleanup): automatically cleanup if afterEach is detected (#80)
You can disable this with the VTL_SKIP_CLEANUP environment variable, but it's recommended to have cleanup work this way. Closes #77 BREAKING CHANGE: If your tests were not isolated before (and you referenced the same component between tests) then this change will break your tests. You should keep your tests isolated, but if you're unable/unwilling to do that right away, then you can run your tests with the environment variable VTL_SKIP_AUTO_CLEANUP set to true.
- Loading branch information
1 parent
297c1c1
commit 394bde7
Showing
13 changed files
with
81 additions
and
32 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 |
---|---|---|
@@ -1 +1,3 @@ | ||
afterEach(require('./dist/vue-testing-library').cleanup) | ||
console.warn( | ||
'The module `@testing-library/vue/cleanup-after-each` has been deprecated and no longer does anything (it is not needed). You no longer need to import this module and can safely remove any import or configuration which imports this module', | ||
) |
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,28 @@ | ||
let render | ||
beforeAll(async () => { | ||
process.env.VTL_SKIP_AUTO_CLEANUP = 'true' | ||
const vtl = await require('@testing-library/vue') | ||
render = vtl.render | ||
}) | ||
|
||
// This one verifies that if VTL_SKIP_AUTO_CLEANUP is set | ||
// then we DON'T auto-wire up the afterEach for folks | ||
test('first test render a vue component', () => { | ||
render({ | ||
template: `<h1>Hello World</h1>`, | ||
}) | ||
|
||
expect(document.body.innerHTML).toMatchInlineSnapshot(` | ||
<div> | ||
<h1>Hello World</h1> | ||
</div> | ||
`) | ||
}) | ||
|
||
test('no cleanup should have happened, renders the first component still', () => { | ||
expect(document.body.innerHTML).toMatchInlineSnapshot(` | ||
<div> | ||
<h1>Hello World</h1> | ||
</div> | ||
`) | ||
}) |
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,20 @@ | ||
import {render} from '@testing-library/vue' | ||
import '@testing-library/jest-dom/extend-expect' | ||
|
||
// This just verifies that by importing VTL in an | ||
// environment which supports afterEach (like jest) | ||
// we'll get automatic cleanup between tests. | ||
test('render the first component', () => { | ||
render({ | ||
template: `<h1>Hello World</h1>`, | ||
}) | ||
expect(document.body.innerHTML).toMatchInlineSnapshot(` | ||
<div> | ||
<h1>Hello World</h1> | ||
</div> | ||
`) | ||
}) | ||
|
||
test('cleans up after each test by default', () => { | ||
expect(document.body.innerHTML).toMatchInlineSnapshot(`""`) | ||
}) |
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
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
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
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