-
Notifications
You must be signed in to change notification settings - Fork 667
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce autoDestroy config option #1240
Conversation
@@ -3,5 +3,6 @@ export default { | |||
mocks: {}, | |||
methods: {}, | |||
provide: {}, | |||
silent: true | |||
silent: true, | |||
autoDestroy: false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
false
should be the default because that is the current behavior
@@ -15,6 +15,12 @@ import { matches } from './matches' | |||
import createDOMEvent from './create-dom-event' | |||
import { throwIfInstancesThrew } from './error' | |||
|
|||
const wrapperInstances = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be an array because when passing a hook function it can happen that multiple wrapper instances were created.
@@ -67,6 +73,17 @@ export default class Wrapper implements BaseWrapper { | |||
) { | |||
this.isFunctionalComponent = true | |||
} | |||
|
|||
const { autoDestroy } = config |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we want to allow overriding this via wrapper options?
@eddyerburgh Can you please review? |
@winniehell, there's an interesting side-effect to this approach. Since this is coupled to the constructor, the last component created will not be destroyed (or the This might not be a problem, but it's a quirk that's probably worth highlighting in the docs. 🤷♀ |
@souldzin Absolutely! Thank you for reminding me! 🙇♂️ EDIT: added a note now |
const { autoDestroy } = config | ||
if (autoDestroy) { | ||
if (autoDestroy instanceof Function) { | ||
autoDestroy(destroyAllInstances) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line is wrong. It will for example result in describe > it > shallowMount > new Wrapper > afterEach
. That way we have a lot of afterEach
calls inside it
s while we only want a single one outside.
I'm not sure how to fix #1240 (comment), so I'm going to close this. I have suggested an alternative approach in #1236 (comment). |
new attempt at #1245 |
This introduces a new
autoDestroy
config option which allows to automatically callwrapper.destroy()
when creating a new wrapper instance or by passing in a custom hook function (such asafterEach
).closes #1236