Skip to content

Commit

Permalink
Added example for container (#114)
Browse files Browse the repository at this point in the history
* Added example for container

This should be merged after testing-library/svelte-testing-library#24 will be published

* Created new section for containers
  • Loading branch information
Artemis330 committed May 20, 2019
1 parent 471b2c6 commit bc0f027
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions docs/svelte-testing-library/intro.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,43 @@ describe('App', () => {
})
```

### Containers

Useful for snapshot tests. You can use query the container if you need more granular tests.

App.svelte

```html
<script>
export let name
</script>

<style>
h1 {
color: purple;
}
</style>

<h1>Hello {name}!</h1>
```

App.spec.js

```javascript
import App from '../src/App.svelte'
import { render, cleanup } from 'svelte-testing-library'
beforeEach(cleanup)
describe('App', () => {
test('should render greeting', () => {
const { container } = render(App, { props: { name: 'world' } })

expect(container.querySelector('h1').innerHTML).toBe('Hello world!')
expect(container.firstChild).toMatchSnapshot()
})

})
```

### Cleanup

You can ensure [`cleanup`](./api#cleanup) is called after each test and import
Expand Down

0 comments on commit bc0f027

Please sign in to comment.