[READ-ONLY] Mirror of https://github.com/vitest-dev/vitest. Next generation testing framework powered by Vite. vitest.dev
test testing-tools vite
12

Configure Feed

Select the types of activity you want to include in your feed.

feat: basic example (#513)

authored by

patak and committed by
GitHub
(Jan 13, 2022, 11:05 AM +0100) 27b8a224 dcfd8bf4

+87
+10
pnpm-lock.yaml
··· 85 85 unplugin-vue-components: 0.17.11_5f0e46dd90b19e6d0d01b34ab1022632 86 86 vitepress: 0.21.4 87 87 88 + examples/basic: 89 + specifiers: 90 + '@vitest/ui': latest 91 + vite: ^2.7.10 92 + vitest: latest 93 + devDependencies: 94 + '@vitest/ui': link:../../packages/ui 95 + vite: 2.7.10 96 + vitest: link:../../packages/vitest 97 + 88 98 examples/lit: 89 99 specifiers: 90 100 happy-dom: '*'
+1
examples/README.md
··· 1 1 | Example | Source | Playground | 2 2 |---|---|---| 3 + | `basic` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/basic) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/basic?terminal=test) | 3 4 | `lit` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/lit) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/lit?terminal=test) | 4 5 | `mocks` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/mocks) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/mocks?terminal=test) | 5 6 | `puppeteer` | [GitHub](https://github.com/vitest-dev/vitest/tree/main/examples/puppeteer) | [Play Online](https://stackblitz.com/github/vitest-dev/vitest/tree/main/examples/puppeteer?terminal=test) |
+5
examples/basic/README.md
··· 1 + # Vitest Demo 2 + 3 + Run `npm test` and change a test or source code to see HMR in action! 4 + 5 + Learn more at https://vitest.dev
+16
examples/basic/package.json
··· 1 + { 2 + "name": "vitest-test", 3 + "private": true, 4 + "main": "index.js", 5 + "license": "MIT", 6 + "type": "module", 7 + "scripts": { 8 + "test": "vitest --ui", 9 + "test:run": "vitest run" 10 + }, 11 + "devDependencies": { 12 + "@vitest/ui": "latest", 13 + "vite": "^2.7.10", 14 + "vitest": "latest" 15 + } 16 + }
+12
examples/basic/vite.config.ts
··· 1 + /// <reference types="vitest" /> 2 + 3 + // Configure Vitest (https://vitest.dev/config) 4 + 5 + import { defineConfig } from 'vite' 6 + 7 + export default defineConfig({ 8 + test: { 9 + /* for example, use global to avoid globals imports (describe, test, expect): */ 10 + // global: true, 11 + }, 12 + })
+21
examples/basic/test/basic.test.ts
··· 1 + import { assert, expect, test } from 'vitest' 2 + 3 + // Edit an assertion and save to see HMR in action 4 + 5 + test('Math.sqrt()', () => { 6 + expect(Math.sqrt(4)).toBe(2) 7 + expect(Math.sqrt(144)).toBe(12) 8 + expect(Math.sqrt(2)).toBe(Math.SQRT2) 9 + }) 10 + 11 + test('JSON', () => { 12 + const input = { 13 + foo: 'hello', 14 + bar: 'world', 15 + } 16 + 17 + const output = JSON.stringify(input) 18 + 19 + expect(output).eq('{"foo":"hello","bar":"world"}') 20 + assert.deepEqual(JSON.parse(output), input, 'matches original') 21 + })
+15
examples/basic/test/suite.test.ts
··· 1 + import { assert, describe, expect, it } from 'vitest' 2 + 3 + describe('suite name', () => { 4 + it('foo', () => { 5 + assert.equal(Math.sqrt(4), 2) 6 + }) 7 + 8 + it('bar', () => { 9 + expect(1 + 1).eq(2) 10 + }) 11 + 12 + it('snapshot', () => { 13 + expect({ foo: 'bar' }).toMatchSnapshot() 14 + }) 15 + })
+7
examples/basic/test/__snapshots__/suite.test.ts.snap
··· 1 + // Vitest Snapshot v1 2 + 3 + exports[`suite name > snapshot 1`] = ` 4 + { 5 + "foo": "bar", 6 + } 7 + `;