-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetest.test.ts
94 lines (83 loc) · 2.4 KB
/
detest.test.ts
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import { expect, runTests, describe, it, test, before, beforeEach } from "./detest.ts"
describe("suite 1", () => {
it("should pass", () => {
expect(1).toBe(1)
})
it("should fail", () => {
expect(1).toBe(2)
})
describe("two", () => {
it("should fail", () => {
expect(1).toBe(2)
})
describe("three", () => {
it("should pass", () => {
expect(2).toBe(2)
})
})
})
})
describe("suite 2", () => {
it("shold be okay", () => {})
})
describe("asnyc tests", () => {
it("should pass", async () => {
let num = await waitForNumber()
expect(num).toBe(42)
})
it("should fail", async () => {
let num = await waitForNumber()
expect(num).toBe(0)
})
})
describe("before", () => {
let a: number
before(() => (a = 1))
test("a === 1", () => expect(a).toBe(1))
})
describe("multiple before", () => {
let a: number
before(() => (a = 1))
before(() => (a = 2))
test("a === 2", () => expect(a).toBe(2))
})
describe("beforeEach", () => {
let a = 0
beforeEach(() => (a = 1))
test("a === 1 should pass", () => {
expect(a).toBe(1)
a++
})
test("a === 2 should fail", () => {
expect(a).toBe(2)
a++
})
test("a === 1 should pass again", () => expect(a).toBe(1))
})
describe("expectations", () => {
describe("not", () => {
test("expect(1).toBe(2) should pass", () => {
expect(1).not.toBe(2)
})
test("expect(2).toBe(2) should fail", () => {
expect(2).not.toBe(2)
})
})
describe("toBeNull", () => {
test("expect(null).toBeNull() should pass", () => expect(null).toBeNull())
test("expect(null).not.toBeNull() should fail", () => expect(null).not.toBeNull())
test("expect(1).toBeNull() should fail", () => expect(1).toBeNull())
test("expect(undefined).toBeNull() should fail", () => expect(undefined).toBeNull())
test("expect([]).toBeNull() should fail", () => expect([]).toBeNull())
})
describe("toBeUndefined", () => {
test("expect(undefined).toBeUndefined() should pass", () => expect(undefined).toBeUndefined())
test("expect(null).toBeUndefined() should fail", () => expect(null).toBeUndefined())
test("expect(1).toBeUndefined() should fail", () => expect(1).toBeUndefined())
test("expect([]).toBeUndefined() should fail", () => expect([]).toBeUndefined())
})
})
function waitForNumber() {
return new Promise(resolve => setTimeout(resolve.bind(this, 42), 100))
}
runTests()