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

Wraps rendered component in a div #11

Merged
merged 1 commit into from
Dec 26, 2018

Conversation

tim-maguire
Copy link
Contributor

@tim-maguire tim-maguire commented Dec 26, 2018

Hello @dfcook really happy you've made this library.

A little problem I've found is that is that you can't use the getQueriesForElement methods on the returned element e.g.

// SimpleButton.vue
<template>
  <button :class="typeClass" @click="clicked">{{ text }}</button>
</template>
// button-test.js
test('renders button with text', () => {
  const buttonText = "Click me; I'm sick"
  const { getByText } = render(SimpleButton, {
    props: { text: buttonText, clicked: () => true }
  })

  getByText(buttonText)
})

As it stands this fails because getByText is querying within the returned element. This scenario works in react-testing-library because it wraps the rendered component in a div.

This PR essentially wraps the vue-test-utils wrapper in a div and passes that to the getQueriesForElement methods.

For good measure it returns the wrapped wrapper as container along with the document.body as baseElement from the render function - to bring it more closely in line with react-testing-library. But maybe this is superfluous..?

I've added a test for the above use case and all the current tests still pass.

- return container and baseElement from render
- pass container to getQueriesForElement
@coveralls
Copy link

Pull Request Test Coverage Report for Build 67

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.8%) to 95.0%

Totals Coverage Status
Change from base Build 65: 0.8%
Covered Lines: 41
Relevant Lines: 42

💛 - Coveralls

Copy link
Collaborator

@dfcook dfcook left a comment

Choose a reason for hiding this comment

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

Great work, thanks

@dfcook dfcook merged commit 5a9314b into testing-library:master Dec 26, 2018
@tim-maguire tim-maguire deleted the add_container branch December 26, 2018 19:21
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.

None yet

3 participants