Skip to content

Update container+baseElement and debug references #321

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

Merged
merged 3 commits into from
Nov 4, 2019
Merged
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
31 changes: 24 additions & 7 deletions docs/vue-testing-library/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It also exposes these methods:
- [`...queries`](#queries)
- [`container`](#container)
- [`baseElement`](#baseelement)
- [`debug()`](#debug)
- [`debug(element)`](#debugelement)
- [`unmount()`](#unmount)
- [`isUnmounted()`](#isunmounted)
- [`html()`](#html)
Expand Down Expand Up @@ -107,20 +107,37 @@ const { getByLabelText, queryAllByTestId } = render(Component)

#### `container`

The containing DOM node of your rendered Vue Component. It's a `div`. This is a
regular DOM node, so you can call `container.querySelector` etc. to inspect the
children.
By default, `Vue Testing Library` will create a `div` and append it to the
`baseElement`. This is where your component will be rendered. If you provide
your own HTMLElement container via this option, it will not be appended to the
`baseElement` automatically.

```js
const table = document.createElement('table')

const { container } = render(TableBody, {
container: document.body.appendChild(table),
})
```

> Tip: To get the root element of your rendered element, use
> `container.firstChild`.

#### `baseElement`

Returns `document.body`, the DOM node where your Vue component is rendered.
`baseElement` is used as the base element for the queries as well as what is
printed when you use `debug()`.

It matches `container` if not custom `baseElement` is provided. If neither
`baseElement` or `container` options are provided, `baseElement` defaults to
`document.body`.

#### `debug(element)`

#### `debug()`
This method is a shortcut for `console.log(prettyDOM(element))`.

This method is a shortcut for `console.log(prettyDOM(baseElement))`.
`element` can either be a DOM element or an array containing DOM elements. It
defaults to `baseElement`

```jsx
import { render } from '@testing-library/vue'
Expand Down