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

feat: Depreciate toBeInTheDOM with replacement #40

Merged
merged 16 commits into from
Jul 18, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,14 @@ This allows you to assert whether an element is present in the document or not.
import 'jest-dom/extend-expect'

// ...
// <span data-testid="count-value">2</span>
// document.body.innerHTML = `<span data-testid="html-element"><span>Html Element</span></span><svg data-testid="svg-element"></svg>`

// const htmlElement = document.querySelector('[data-testid="html-element"]')
// const svgElement = document.querySelector('[data-testid="html-element"]')
// const detachedElement = document.createElement('div')

expect(queryByTestId(container, 'count-value').toBeInTheDocument()
Copy link
Member

Choose a reason for hiding this comment

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

I would've thought this line was also going to be replaced to use some of the other elements you define above that are indeed in the document.

I'd even insist in changing it merely on the ground that this is referencing a helper function in dom-testing-library, probably since this README was created based on that other library's README.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I am sorry! Great catch!

expect(queryByTestId(container, 'count-value1')).not.toBeInTheDocument()
expect(detacthedElement).not.toBeInTheDocument()
// ...
```

Expand Down Expand Up @@ -363,10 +368,12 @@ expect(getByText(container, 'LINK')).not.toBeDisabled()

### `toBeInTheDOM`

> Please use [`toBeInTheDocument`](#tobeinthedocument) for searching the entire document.
> Note: The differences between `toBeInTheDOM` and `toBeInTheDocument` are significant. Replacing all uses of `toBeInTheDOM` with `toBeInTheDocument` will likely cause unintended consequences in your tests. Please make sure when replacing `toBeInTheDOM` to read through the replacements below to see which use case works better for your needs.

> Please use [`toContainElement`](#tocontainelement) for searching a specific container.

> Please use [`toBeInTheDocument`](#tobeinthedocument) for searching the entire document.

## Inspiration

This whole library was extracted out of Kent C. Dodds' [dom-testing-library][],
Expand Down
4 changes: 4 additions & 0 deletions src/__tests__/to-be-in-the-document.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ test('.toBeInTheDocument', () => {
const svgElement = document.querySelector('[data-testid="html-element"]')
const detachedElement = document.createElement('div')
const fakeElement = {thisIsNot: 'an html element'}
const undefinedElement = undefined
const nullElement = null

expect(htmlElement).toBeInTheDocument()
expect(svgElement).toBeInTheDocument()
Expand All @@ -17,4 +19,6 @@ test('.toBeInTheDocument', () => {
expect(() => expect(svgElement).not.toBeInTheDocument()).toThrowError()
expect(() => expect(detachedElement).toBeInTheDocument()).toThrowError()
expect(() => expect(fakeElement).toBeInTheDocument()).toThrowError()
expect(() => expect(undefinedElement).toBeInTheDocument()).toThrowError()
expect(() => expect(nullElement).toBeInTheDocument()).toThrowError()
})