File tree 3 files changed +27
-17
lines changed
3 files changed +27
-17
lines changed Original file line number Diff line number Diff line change 4
4
5
5
## Installation
6
6
7
- ` npm i -D svelte -testing-library `
7
+ ` npm i -D svlt -testing-library `
8
8
9
9
## Usage
10
10
11
11
App.svelte
12
12
13
13
``` html
14
14
<script >
15
- export let name;
15
+ export let name
16
16
</script >
17
17
18
18
<style >
@@ -27,13 +27,23 @@ App.svelte
27
27
App.spec.js
28
28
29
29
``` 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
+ })
39
49
```
Original file line number Diff line number Diff line change @@ -2,12 +2,12 @@ import {getQueriesForElement} from 'dom-testing-library'
2
2
3
3
export * from 'dom-testing-library'
4
4
const 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' ) )
7
7
8
8
const rendered = new Component ( {
9
- target : container ,
10
- props ,
9
+ ... options ,
10
+ target ,
11
11
} )
12
12
13
13
mountedContainers . add ( rendered )
Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ import 'jest-dom/extend-expect'
5
5
afterEach ( cleanup )
6
6
describe ( 'queries' , ( ) => {
7
7
test ( 'getByText' , ( ) => {
8
- const { getByText} = render ( App , { name : 'world' } )
8
+ const { getByText} = render ( App , { props : { name : 'world' } } )
9
9
10
10
expect ( getByText ( 'Hello world!' ) ) . toBeInTheDocument ( )
11
11
} )
12
12
13
13
test ( 'click button' , async ( ) => {
14
- const { getByText} = render ( App , { name : 'world' } )
14
+ const { getByText} = render ( App , { props : { name : 'world' } } )
15
15
16
16
fireEvent . click ( getByText ( 'Button Text' ) )
17
17
You can’t perform that action at this time.
0 commit comments