Skip to content

Conversation

blimmer
Copy link
Contributor

@blimmer blimmer commented Jun 30, 2021

This update is in response to a conversation between @maxarndt and I here. The workaround of resetting window.location has some pitfalls, so this PR updates the documentation to only recommend using abstract mode.

})
```

2. **Reset the window location `afterEach`**. If you don't want to pass an
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 isn't the best option for people - they should instead use abstract mode, so don't recommend it.


// Unlike the router in `hash` mode, the initial routing stack is empty. So,
// you need to push an initial route to the stack.
await router.push('/')
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @maxarndt - this adds the initial push you mentioned in testing-library/vue-testing-library#210 (comment)

2. **Reset the window location `afterEach`**. If you don't want to pass an
instantiated Router, you can instead reset the `window.location` after each
test, like this:
To reduce boilerplate, you can create a custom render function to use throughout
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@maxarndt - if you've got some time for a contribution, it would be great to pull over the Custom Render setup guide from the react-testing-library docs (https://testing-library.com/docs/react-testing-library/setup#custom-render) to the currently blank setup page of Vue Testing Library (https://testing-library.com/docs/vue-testing-library/setup). Then, we could link to the custom render docs from this FAQ.

Copy link
Member

@afontcu afontcu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! We can work on the custom render section in a upcoming PR.

thanks and nice catch!

@afontcu afontcu merged commit 49e6d83 into testing-library:main Jun 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants