From 41c7c5e7402b14b615b9cb0b7d909d11177f860d Mon Sep 17 00:00:00 2001 From: Eduardo Rabelo Date: Mon, 5 Aug 2019 11:43:15 +1200 Subject: [PATCH 1/3] feat: fix README demo + live demo in CodeSandbox with Tests --- README.md | 49 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 748522a..5479dac 100644 --- a/README.md +++ b/README.md @@ -91,11 +91,21 @@ primary guiding principle is: ## Example +You can check the live example at CodeSandbox, "Browser" tab renders App.svelte and "Tests" tab runs App.spec.js + +- **Live demo:** https://codesandbox.io/s/confident-johnson-q8iv7 + App.svelte ```html

Hello {name}!

+ + ``` App.spec.js ```javascript -import App from '../src/App.svelte' -import {render} from '@testing-library/svelte' -describe('App', () => { - test('should render greeting', () => { - const {getByText} = render(App, {props: {name: 'world'}}) +import App from "./App.svelte"; +import { + render, + cleanup, + fireEvent, + waitForElement +} from "@testing-library/svelte"; +import "@testing-library/jest-dom/extend-expect"; + +afterEach(cleanup); + +describe("App", () => { + test("should render greeting", () => { + const { getByText } = render(App, { props: { name: "world" } }); - expect(getByText('Hello world!')) - }) + expect(getByText("Hello world!")); + }); - test('should change button text after click', async () => { - const {getByText} = render(App, {props: {name: 'world'}}) + test("should change button text after click", async () => { + const { getByText } = render(App, { props: { name: "world" } }); - fireEvent.click(getByText('Button Text')) + fireEvent.click(getByText("Button Text")); - const button = await waitForElement(() => getByText('Button Clicked')) + const button = await waitForElement(() => getByText("Button Clicked")); - expect(button).toBeInTheDocument() - }) -}) + expect(button).toBeInTheDocument(); + }); +}); ``` ## Installation From 6f7c4872d942ade93b17e5938e88d223a10fb4ed Mon Sep 17 00:00:00 2001 From: Eduardo Rabelo Date: Mon, 5 Aug 2019 12:12:13 +1200 Subject: [PATCH 2/3] chore: update codesandbox link name --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 5479dac..db32456 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ primary guiding principle is: You can check the live example at CodeSandbox, "Browser" tab renders App.svelte and "Tests" tab runs App.spec.js -- **Live demo:** https://codesandbox.io/s/confident-johnson-q8iv7 +- **Live demo:** https://codesandbox.io/embed/live-demo-svelte-testing-library-q8iv7 App.svelte From 566a01be9816e1a7fd67d08a985ef7d051cbc7e5 Mon Sep 17 00:00:00 2001 From: Eduardo Rabelo Date: Mon, 5 Aug 2019 12:21:15 +1200 Subject: [PATCH 3/3] feat: use codesandbox editor not embed url --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index db32456..7f6a1bd 100644 --- a/README.md +++ b/README.md @@ -93,7 +93,7 @@ primary guiding principle is: You can check the live example at CodeSandbox, "Browser" tab renders App.svelte and "Tests" tab runs App.spec.js -- **Live demo:** https://codesandbox.io/embed/live-demo-svelte-testing-library-q8iv7 +- **Live demo:** https://codesandbox.io/s/live-demo-svelte-testing-library-q8iv7 App.svelte