From 15695efdf90bb09647bd4d70671e0baa9ba38a48 Mon Sep 17 00:00:00 2001 From: Emanuele Date: Sat, 18 May 2019 18:05:41 +0100 Subject: [PATCH 1/2] Added example for container This should be merged after https://github.com/testing-library/svelte-testing-library/pull/24 will be published --- docs/svelte-testing-library/intro.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/svelte-testing-library/intro.md b/docs/svelte-testing-library/intro.md index 3b285c876..8a75b1ab1 100644 --- a/docs/svelte-testing-library/intro.md +++ b/docs/svelte-testing-library/intro.md @@ -58,13 +58,14 @@ describe('App', () => { }) test('should change button text after click', async () => { - const { getByText } = render(App, { props: { name: 'world' } }) + const { getByText, container } = render(App, { props: { name: 'world' } }) fireEvent.click(getByText('Button Text')) const button = await waitForElement(() => getByText('Button Clicked')) expect(button).toBeInTheDocument() + expect(container.firstChild).toMatchSnapshot() }) }) ``` From dcfe318441fb119c11b60ce962a5870179d4ebfd Mon Sep 17 00:00:00 2001 From: Emanuele Date: Mon, 20 May 2019 08:53:42 +0100 Subject: [PATCH 2/2] Created new section for containers --- docs/svelte-testing-library/intro.md | 38 +++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/docs/svelte-testing-library/intro.md b/docs/svelte-testing-library/intro.md index 8a75b1ab1..e4e61a734 100644 --- a/docs/svelte-testing-library/intro.md +++ b/docs/svelte-testing-library/intro.md @@ -58,15 +58,51 @@ describe('App', () => { }) test('should change button text after click', async () => { - const { getByText, container } = render(App, { props: { name: 'world' } }) + const { getByText } = render(App, { props: { name: 'world' } }) fireEvent.click(getByText('Button Text')) const button = await waitForElement(() => getByText('Button Clicked')) expect(button).toBeInTheDocument() + }) +}) +``` + +### Containers + +Useful for snapshot tests. You can use query the container if you need more granular tests. + +App.svelte + +```html + + + + +

Hello {name}!

+``` + +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() }) + }) ```