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
2 changed files
with
11 additions
and
67 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,19 @@ | ||
import { assert, expect, it, suite, test } from 'vitest' | ||
import { two } from '../src/submodule' | ||
import { timeout } from '../src/timeout' | ||
import { it } from 'vitest' | ||
|
||
test('Math.sqrt()', async () => { | ||
assert.equal(Math.sqrt(4), two) | ||
assert.equal(Math.sqrt(2), Math.SQRT2) | ||
expect(Math.sqrt(144)).toStrictEqual(12) | ||
// await new Promise(resolve => setTimeout(resolve, 3000)) | ||
}) | ||
|
||
test('JSON', () => { | ||
const input = { | ||
foo: 'hello', | ||
bar: 'world', | ||
} | ||
|
||
const output = JSON.stringify(input) | ||
const isDev = process.env.NODE_ENV === 'development' | ||
|
||
expect(input).toEqual({ | ||
foo: 'hello', | ||
bar: 'world', | ||
if (!isDev) { | ||
it('prod only tests', () => { | ||
/* ... */ | ||
}) | ||
expect(output).toEqual('{"foo":"hello","bar":"world"}') | ||
assert.deepEqual(JSON.parse(output), input, 'matches original') | ||
}) | ||
} | ||
|
||
test('mode and NODE_ENV is test by default', () => { | ||
expect(process.env.NODE_ENV).toBe('test') | ||
expect(import.meta.env.MODE).toBe('test') | ||
// Now in Vitest v0.10.1 | ||
it.skipIf(isDev)('prod only tests', () => { | ||
/* ... */ | ||
}) | ||
|
||
test('assertion is callable', () => { | ||
const str = '13' | ||
expect(str).to.be.a('string') | ||
expect(str).not.to.be.a('number') | ||
it.runIf(isDev)('dev only tests', () => { | ||
/* ... */ | ||
}) | ||
|
||
const hi = suite('suite') | ||
|
||
hi.test('expect truthy', () => { | ||
expect({}).toBeTruthy() | ||
expect(null).not.toBeTruthy() | ||
}) | ||
|
||
// Remove .skip to test async fail by timeout | ||
test.skip('async with timeout', async () => { | ||
return new Promise((resolve) => { | ||
setTimeout(() => { | ||
resolve() | ||
}, 200) | ||
}) | ||
}, 100) | ||
|
||
it('timeout', () => new Promise(resolve => setTimeout(resolve, timeout))) | ||
|
||
it.fails('deprecated done callback', (done) => { | ||
done() | ||
}) | ||
|
||
const shouldSkip = true | ||
|
||
it.skipIf(shouldSkip)('skipped', () => { | ||
throw new Error('foo') | ||
}) | ||
it.skipIf(!shouldSkip)('not skipped', () => { | ||
expect(1).toBe(1) | ||
}) | ||
it.runIf(!shouldSkip)('skipped 2', () => { | ||
throw new Error('foo') | ||
}) | ||
it.runIf(shouldSkip)('not skipped 2', () => { | ||
expect(1).toBe(1) | ||
}) |