Skip to content
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

Closed
wants to merge 1 commit into from
Closed

Introduce autoDestroy config option #1240

wants to merge 1 commit into from

Conversation

winniehell
Copy link
Contributor

This introduces a new autoDestroy config option which allows to automatically call wrapper.destroy() when creating a new wrapper instance or by passing in a custom hook function (such as afterEach).

closes #1236

@@ -3,5 +3,6 @@ export default {
mocks: {},
methods: {},
provide: {},
silent: true
silent: true,
autoDestroy: false
Copy link
Contributor Author

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 = []
Copy link
Contributor Author

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
Copy link
Contributor Author

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?

@winniehell
Copy link
Contributor Author

@eddyerburgh Can you please review?

@souldzin
Copy link
Contributor

souldzin commented May 22, 2019

@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 autoDestroy callback will not called).

This might not be a problem, but it's a quirk that's probably worth highlighting in the docs. 🤷‍♀

@winniehell
Copy link
Contributor Author

winniehell commented May 22, 2019

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)
Copy link
Contributor Author

@winniehell winniehell May 22, 2019

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 its while we only want a single one outside.

@winniehell
Copy link
Contributor Author

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).

@winniehell winniehell closed this May 22, 2019
@winniehell winniehell deleted the winniehell-autoremove branch May 22, 2019 16:22
@winniehell
Copy link
Contributor Author

new attempt at #1245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support cleaning up wrappers automagically
2 participants