Skip to content

Commit c386099

Browse files
authored
feat: spread all of options on component (#2)
1 parent 2b95e85 commit c386099

File tree

3 files changed

+27
-17
lines changed

3 files changed

+27
-17
lines changed

Diff for: README.md

+21-11
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,15 @@
44

55
## Installation
66

7-
`npm i -D svelte-testing-library`
7+
`npm i -D svlt-testing-library`
88

99
## Usage
1010

1111
App.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
2727
App.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
```

Diff for: src/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@ import {getQueriesForElement} from 'dom-testing-library'
22

33
export * from 'dom-testing-library'
44
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'))
77

88
const rendered = new Component({
9-
target: container,
10-
props,
9+
...options,
10+
target,
1111
})
1212

1313
mountedContainers.add(rendered)

Diff for: tests/queries.spec.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ import 'jest-dom/extend-expect'
55
afterEach(cleanup)
66
describe('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

0 commit comments

Comments
 (0)