File tree Expand file tree Collapse file tree 3 files changed +27
-17
lines changed Expand file tree Collapse file tree 3 files changed +27
-17
lines changed Original file line number Diff line number Diff line change 44
55## Installation
66
7- ` npm i -D svelte -testing-library `
7+ ` npm i -D svlt -testing-library `
88
99## Usage
1010
1111App.svelte
1212
1313``` html
1414<script >
15- export let name;
15+ export let name
1616 </script >
1717
1818<style >
@@ -27,13 +27,23 @@ App.svelte
2727App.spec.js
2828
2929``` javascript
30- import App from " ../src/App.svelte" ;
31- import { render } from " ../src" ;
32- describe (" App" , () => {
33- test (" should render" , () => {
34- const { getByText } = render (App, { name: " world" });
35-
36- expect (getByText (" Hello world!" ));
37- });
38- });
30+ import App from ' ../src/App.svelte'
31+ import {render } from ' ../src'
32+ describe (' App' , () => {
33+ test (' should render greeting' , () => {
34+ const {getByText } = render (App, {props: {name: ' world' }})
35+
36+ expect (getByText (' Hello world!' ))
37+ })
38+
39+ test (' should change button text after click' , async () => {
40+ const {getByText } = render (App, {props: {name: ' world' }})
41+
42+ fireEvent .click (getByText (' Button Text' ))
43+
44+ const button = await waitForElement (() => getByText (' Button Clicked' ))
45+
46+ expect (button).toBeInTheDocument ()
47+ })
48+ })
3949```
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ import {getQueriesForElement} from 'dom-testing-library'
22
33export * from 'dom-testing-library'
44const mountedContainers = new Set ( )
5- export const render = ( Component , props ) => {
6- const container = document . body . appendChild ( document . createElement ( 'div' ) )
5+ export const render = ( Component , options ) => {
6+ const target = document . body . appendChild ( document . createElement ( 'div' ) )
77
88 const rendered = new Component ( {
9- target : container ,
10- props ,
9+ ... options ,
10+ target ,
1111 } )
1212
1313 mountedContainers . add ( rendered )
Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ import 'jest-dom/extend-expect'
55afterEach ( cleanup )
66describe ( 'queries' , ( ) => {
77 test ( 'getByText' , ( ) => {
8- const { getByText} = render ( App , { name : 'world' } )
8+ const { getByText} = render ( App , { props : { name : 'world' } } )
99
1010 expect ( getByText ( 'Hello world!' ) ) . toBeInTheDocument ( )
1111 } )
1212
1313 test ( 'click button' , async ( ) => {
14- const { getByText} = render ( App , { name : 'world' } )
14+ const { getByText} = render ( App , { props : { name : 'world' } } )
1515
1616 fireEvent . click ( getByText ( 'Button Text' ) )
1717
You can’t perform that action at this time.
0 commit comments