vitest/test/basic.test.ts
2021-12-05 15:49:37 +08:00

35 lines
689 B
TypeScript

import { expect, test, assert, suite } from '../src'
test('Math.sqrt()', () => {
assert.equal(Math.sqrt(4), 2)
assert.equal(Math.sqrt(2), Math.SQRT2)
expect(Math.sqrt(144)).toStrictEqual(12)
})
test('JSON', () => {
const input = {
foo: 'hello',
bar: 'world',
}
const output = JSON.stringify(input)
expect(output).eq('{"foo":"hello","bar":"world"}')
assert.deepEqual(JSON.parse(output), input, 'matches original')
})
test('async', async() => {
return new Promise((resolve) => {
setTimeout(() => {
resolve()
}, 200)
})
})
const hi = suite('suite')
hi.test('expect truthy', () => {
expect({}).toBeTruthy()
expect(null).not.toBeTruthy()
})