-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.test.ts
More file actions
56 lines (42 loc) · 1.11 KB
/
example.test.ts
File metadata and controls
56 lines (42 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import { expect, test } from 'vitest'
test('example test', () => {
const name = 'World'
expect(`Hello, ${name}!`).toBe('Hello, World!')
expect(1 + 1).toBe(2)
expect(2 + 1).not.toBe(4)
})
test("test to be true or false", () => {
const isTrue = true;
const isFalse = false;
expect(isTrue).toBe(true);
expect(isFalse).toBe(false);
expect(1).toBeTruthy();
expect(0).toBeFalsy();
});
test("test to be null or undefined", () => {
const value = null;
const anotherValue = undefined;
expect(value).toBeNull();
expect(anotherValue).toBeUndefined();
expect(anotherValue).not.toBeDefined();
});
test("test to be greater than or less than", () => {
const a = 5;
const b = 10;
expect(a).toBeLessThan(b);
expect(b).toBeGreaterThan(a);
expect(3).toBeLessThanOrEqual(3);
expect(4).toBeGreaterThanOrEqual(4);
});
test("test number",() => {
expect(5).toBeGreaterThan(3);
//5比3大
expect(2).toBeLessThan(3);
//2比3小
});
test("test string", () => {
const str = "Hello, World!";
expect(str).toContain("World");
expect(str).toMatch(/Hello/);
expect(str.length).toBe(13);
});