-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
54 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
slug: svelte-example | ||
title: Jest Preview with Svelte | ||
description: If you use Jest to write tests for Svelte, you can also use Jest Preview to write and debug your tests faster | ||
authors: [nvh95] | ||
tags: [jest-preview, svelte, example] | ||
image: /img/svelte-support.jpg | ||
--- | ||
|
||
[jest-preview](https://www.npmjs.com/package/jest-preview) is initially designed to work with jest, react and react-testing-library. However, the package is framework-agnostic, and you can use it with any testing libraries. Today, we add [an example](https://github.com/nvh95/jest-preview/tree/main/examples/svelte) of using it with [**Svelte**](https://svelte.dev) and [**Svelte Testing Library**](https://testing-library.com/docs/svelte-testing-library/intro/) | ||
|
||
<!--truncate--> | ||
|
||
![Use Jest Preview with Svelte](./svelte-animated.gif) | ||
|
||
Now, you can easily preview your UI in Jest when using Svelte just by 2 steps: | ||
|
||
1. Open Jest Preview Dashboard: | ||
|
||
```bash | ||
jest-preview | ||
``` | ||
|
||
2. Add `debug()` to wherever you want to preview: | ||
|
||
```diff | ||
import { render, fireEvent, screen } from '@testing-library/svelte'; | ||
import { debug } from 'jest-preview'; | ||
import App from '../../App.svelte'; | ||
|
||
describe('Counter Component', () => { | ||
it('it changes count when button is clicked', async () => { | ||
render(App); | ||
const button = screen.getByText(/Clicks:/); | ||
expect(button.innerHTML).toBe('Clicks: 0'); | ||
await fireEvent.click(button); | ||
expect(button.innerHTML).toBe('Clicks: 1'); | ||
|
||
+ debug(); | ||
}); | ||
}); | ||
``` | ||
|
||
That's it. You can see the full example and detailed instruction at https://github.com/nvh95/jest-preview/tree/main/examples/svelte. | ||
|
||
<!-- TODO: After copying README.md to docs page, update the link here. --> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.