Skip to content

Commit 1b70c63

Browse files
authored
Merge pull request #334 from mihar-22/svelte
docs(svelte): improve component api description + recommend better transformer
2 parents 1957b04 + 12d8c11 commit 1b70c63

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

docs/svelte-testing-library/api.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ Please refer to the
5050

5151
### Results
5252

53-
| Result | Description |
54-
| ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55-
| `container` | The HTML element the component is mounted into. |
56-
| `component` | The newly created Svelte component. This is mostly useful for testing exported functions or cases where manipulating the DOM doesn't fit. Outside of said cases avoid using the component directly to build tests, instead of interacting with the rendered Svelte component, work with the DOM . |
57-
| `debug` | Logs the `container` using [prettyDom](https://testing-library.com/docs/dom-testing-library/api-helpers#prettydom). |
58-
| `unmount` | Unmounts the component from the `target` by calling `component.$destroy()`. |
59-
| `rerender` | Calls render again destroying the old component, and mounting the new component on the original `target` with any new options passed in. |
60-
| `...queries` | Returns all [query functions](https://testing-library.com/docs/dom-testing-library/api-queries) that are binded to the `container`. If you pass in `query` arguments than this will be those, otherwise all. |
53+
| Result | Description |
54+
| ------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
55+
| `container` | The HTML element the component is mounted into. |
56+
| `component` | The newly created Svelte component. Generally, this should only be used when testing exported functions, or when you're testing developer facing API's. Outside of said cases avoid using the component directly to build tests, instead of interacting with the rendered Svelte component, work with the DOM. Have a read of [Avoid the Test User](https://kentcdodds.com/blog/avoid-the-test-user) by Kent C. Dodds to understand the difference between the **end user** and **developer user**. |
57+
| `debug` | Logs the `container` using [prettyDom](https://testing-library.com/docs/dom-testing-library/api-helpers#prettydom). |
58+
| `unmount` | Unmounts the component from the `target` by calling `component.$destroy()`. |
59+
| `rerender` | Calls render again destroying the old component, and mounting the new component on the original `target` with any new options passed in. |
60+
| `...queries` | Returns all [query functions](https://testing-library.com/docs/dom-testing-library/api-queries) that are binded to the `container`. If you pass in `query` arguments than this will be those, otherwise all. |
6161

6262
## `cleanup`
6363

docs/svelte-testing-library/setup.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,10 @@ with any testing framework and runner you're comfortable with.
2828
2929
3. You'll need to compile the Svelte components before using them in Jest, so
3030
we need to install
31-
[jest-transform-svelte](https://github.com/rspieker/jest-transform-svelte)
31+
[svelte-jester](https://github.com/mihar-22/svelte-jester)
3232
3333
```
34-
npm install --save-dev jest-transform-svelte
34+
npm install --save-dev svelte-jester
3535
```
3636
3737
4. Add the following Jest configuration to your `package.json`
@@ -40,7 +40,7 @@ with any testing framework and runner you're comfortable with.
4040
{
4141
"jest": {
4242
"transform": {
43-
"^.+\\.svelte$": "jest-transform-svelte"
43+
"^.+\\.svelte$": "svelte-jester"
4444
},
4545
"moduleFileExtensions": ["js", "svelte"]
4646
}
@@ -71,3 +71,10 @@ with any testing framework and runner you're comfortable with.
7171
```
7272
npm run test
7373
```
74+
75+
## Babel / Preprocessors
76+
77+
If you'd like to also include [Babel](https://babeljs.io/) or any
78+
[Svelte preprocessors](https://github.com/kaisermann/svelte-preprocess) then
79+
simply follow the instructions over at
80+
[svelte-jester](https://github.com/mihar-22/svelte-jester#babel).

0 commit comments

Comments
 (0)