Skip to content

Commit

Permalink
docs: Add blog post for Svelte
Browse files Browse the repository at this point in the history
  • Loading branch information
nvh95 committed Jul 2, 2022
1 parent f5e5fc5 commit dff5e75
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 6 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,11 @@ You also need to start the Jest Preview Server by running the CLI `jest-preview`

## Examples

- Use with [Vite](https://vitejs.dev/): [Example with Vite](https://www.jest-preview.com/docs/examples/vite-react)
- Use with [Create React App](https://create-react-app.dev/): [Example with CRA](https://www.jest-preview.com/docs/examples/create-react-app)
- Use with [NextJs Rust Compiler](https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compiler): [Example with NextJs Rust Compiler](https://www.jest-preview.com/docs/examples/next-rust)
- Use with [NextJS Babel](https://nextjs.org/docs/testing#setting-up-jest-with-babel): [Example with CRA](https://www.jest-preview.com/docs/examples/next-babel)
- Use with [Vite React](https://vitejs.dev/): https://www.jest-preview.com/docs/examples/vite-react
- Use with [Create React App](https://create-react-app.dev/): https://www.jest-preview.com/docs/examples/create-react-app
- Use with [NextJs Rust Compiler](https://nextjs.org/docs/testing#setting-up-jest-with-the-rust-compiler): https://www.jest-preview.com/docs/examples/next-rust
- Use with [NextJS Babel](https://nextjs.org/docs/testing#setting-up-jest-with-babel): https://www.jest-preview.com/docs/examples/next-babel
- Use with [Svelte](https://svelte.dev): https://www.jest-preview.com/docs/examples/svelte

## Feedback

Expand Down
5 changes: 3 additions & 2 deletions examples/svelte/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Use with Svelte

This example demonstrates how to use `jest-preview` with [`Svelte`](https://svelte.dev) and [`Svelte Testing Library`](https://testing-library.com/docs/svelte-testing-library/intro/)
This example demonstrates how to use `jest-preview` with [**Svelte**](https://svelte.dev) and [**Svelte Testing Library**](https://testing-library.com/docs/svelte-testing-library/intro/)

## Install Jest

Expand All @@ -18,11 +18,12 @@ Install Jest Preview
npm install --save-dev jest-preview
```

Configure code transforms as follow:
[Configure code transforms](https://www.jest-preview.com/docs/getting-started/installation#2-configure-jests-transform-to-transform-css-and-files) as follow:

```js
// jest.config.js
transform: {
// ...
"^.+\\.(css|scss|sass)$": "jest-preview/transforms/css",
"^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)": "jest-preview/transforms/file",
}
Expand Down
46 changes: 46 additions & 0 deletions website/blog/2022-07-02-svelte-example/index.md
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.
Binary file added website/static/img/svelte-support.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit dff5e75

Please sign in to comment.