Skip to content

Commit 4e52eb4

Browse files
committed
docs(svelte): props can now be passed in directly
ref: testing-library/svelte-testing-library#62
1 parent 1b70c63 commit 4e52eb4

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

docs/svelte-testing-library/api.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ tells Svelte to apply any new changes to the DOM.
2525

2626
## `render`
2727

28-
```jsx
28+
```js
2929
import { render } from '@testing-library/svelte'
3030

3131
const { results } = render(
@@ -41,6 +41,20 @@ These are the options you pass when instantiating your Svelte `Component`.
4141
Please refer to the
4242
[Client-side component API](https://svelte.dev/docs#Client-side_component_API).
4343

44+
📝 If the only option you're passing in is `props`, then you can just pass them
45+
in directly.
46+
47+
```js
48+
// With options.
49+
const { results } = render(YourComponent, {
50+
target: MyTarget,
51+
props: { myProp: 'value' },
52+
})
53+
54+
// Props only.
55+
const { results } = render(YourComponent, { myProp: 'value' })
56+
```
57+
4458
### Render Options
4559

4660
| Option | Description | Default |
@@ -69,7 +83,7 @@ Unmounts the component from the container and destroys the container.
6983
test. If you'd like to disable this then set `process.env.STL_SKIP_AUTO_CLEANUP`
7084
to true or import `dont-clean-up-after-each` from the library.
7185

72-
```jsx
86+
```js
7387
import { render, cleanup } from '@testing-library/svelte'
7488

7589
afterEach(() => {

docs/svelte-testing-library/example.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,14 @@ import { render, fireEvent } from '@testing-library/svelte'
3333
import Comp from '../Comp'
3434

3535
test('shows proper heading when rendered', () => {
36-
const { getByText } = render(Comp, { props: { name: 'World' } })
36+
const { getByText } = render(Comp, { name: 'World' })
3737

3838
expect(getByText('Hello World!')).toBeInTheDocument()
3939
})
4040

4141
// Note: This is as an async test as we are using `fireEvent`
4242
test('changes button text on click', async () => {
43-
const { getByText } = render(Comp, { props: { name: 'World' } })
43+
const { getByText } = render(Comp, { name: 'World' })
4444
const button = getByText('Button')
4545

4646
// Using await when firing events is unique to the svelte testing library because

0 commit comments

Comments
 (0)