Skip to content

Commit

Permalink
docs: add atk's official solid test case in examples (#866)
Browse files Browse the repository at this point in the history
  • Loading branch information
atk committed Feb 28, 2022
1 parent 661aa81 commit 1335d5c
Show file tree
Hide file tree
Showing 8 changed files with 3,225 additions and 1,193 deletions.
10 changes: 10 additions & 0 deletions examples/solid/components/Hello.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable react/prop-types */
import { createSignal } from 'solid-js'

export const Hello = (props) => {
const [times, setTimes] = createSignal(2)
return <>
<div>{`${props.count} x ${times()} = ${props.count * times()}`}</div>
<button onClick={() => setTimes(t => t + 1)}>x1</button>
</>
}
17 changes: 17 additions & 0 deletions examples/solid/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "@vitest/test-solid",
"private": true,
"scripts": {
"test": "vitest",
"coverage": "vitest --coverage"
},
"dependencies": {
"solid-js": "^1.3.8"
},
"devDependencies": {
"jsdom": "*",
"solid-start": "next",
"solid-testing-library": "0.3.0",
"vitest": "latest"
}
}
27 changes: 27 additions & 0 deletions examples/solid/test/Hello.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { describe, expect, test } from 'vitest'
import { fireEvent, render } from 'solid-testing-library'
import { Hello } from '../components/Hello'

describe('<Hello />', () => {
test('renders', () => {
const { container, unmount } = render(() => <Hello count={4} />)
expect(container.innerHTML).toMatchSnapshot()
unmount()
})

test('updates', async() => {
const { container, unmount, queryByText } = render(() => <Hello count={4} />)
const button = queryByText('x1')
const buttonClicked = new Promise((resolve) => {
const handler = (ev) => {
button.removeEventListener('click', handler)
resolve(ev)
}
button.addEventListener('click', handler)
})
fireEvent.click(button)
await buttonClicked
expect(container.innerHTML).toMatchSnapshot()
unmount()
})
})
5 changes: 5 additions & 0 deletions examples/solid/test/__snapshots__/Hello.test.jsx.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Vitest Snapshot v1

exports[`<Hello /> > renders 1`] = `"<div>4 x 2 = 8</div><button>x1</button>"`;

exports[`<Hello /> > updates 1`] = `"<div>4 x 3 = 12</div><button>x1</button>"`;
23 changes: 23 additions & 0 deletions examples/solid/vite.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/// <reference types="vitest" />
/// <reference types="vite/client" />

import { defineConfig } from 'vite'
import solid from 'solid-start' // or use 'vite-plugin-solid' instead

export default defineConfig({
test: {
environment: 'jsdom',
transformMode: {
web: [/.[jt]sx?/],
},
deps: {
inline: [/solid-js/],
},
threads: false,
isolate: false,
},
plugins: [solid()],
resolve: {
conditions: ['development', 'browser'],
},
})
2 changes: 2 additions & 0 deletions packages/ui/client/auto-imports.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ declare global {
const reactify: typeof import('@vueuse/core')['reactify']
const reactifyObject: typeof import('@vueuse/core')['reactifyObject']
const reactive: typeof import('vue')['reactive']
const reactiveComputed: typeof import('@vueuse/core')['reactiveComputed']
const reactiveOmit: typeof import('@vueuse/core')['reactiveOmit']
const reactivePick: typeof import('@vueuse/core')['reactivePick']
const readonly: typeof import('vue')['readonly']
const ref: typeof import('vue')['ref']
Expand Down
7 changes: 0 additions & 7 deletions packages/vitest/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -465,13 +465,6 @@ Repository: git:https://github.com/kpdecker/jsdiff.git
---------------------------------------

## eastasianwidth
License: MIT
By: Masaki Komagata
Repository: git:https://github.com/komagata/eastasianwidth.git

---------------------------------------

## emoji-regex
License: MIT
By: Mathias Bynens
Expand Down
Loading

0 comments on commit 1335d5c

Please sign in to comment.