This repository has been archived by the owner on May 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
basic-test.ts
151 lines (129 loc) · 4.71 KB
/
basic-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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import { assert } from 'chai';
import { wait } from 'f-promise';
import * as fMocha from '../src';
import { setup } from '../src/setup';
setup();
describe('basic test', () => {
it('sync works', () => {
assert(true, 'got true');
});
it('async works like sync', () => {
assert(true, 'got true before wait');
wait<void>(cb => setTimeout(cb, 0));
assert(true, 'got true after wait');
});
it.skip('skip', () => {
assert(true, 'not executed because of skip');
});
it('should export default the mocha UI function', () => {
assert(fMocha instanceof Function, 'default export should be a function');
assert((fMocha as Function).name === 'fMochaInterface', 'default export should be the `fMochaInterface` function');
});
});
describe('basic test on before', () => {
describe('sync test', () => {
let expected: boolean;
before('init expected value', () => {
expected = true;
});
it('check expected value set in before', () => {
assert(expected, 'got expected value set in before');
expected = false;
});
it('check expected value set in before but changed in previous it', () => {
assert(!expected, 'got expected value set in before');
});
});
describe('async test', () => {
let expected: boolean;
before('init expected value', () => {
assert(true, 'got false before wait');
wait<void>(cb => setTimeout(cb, 0));
assert(true, 'got true after wait');
expected = true;
});
it('check expected value set in before', () => {
assert(expected, 'got expected value set in before');
expected = false;
});
it('check expected value set in before but changed in previous it', () => {
assert(!expected, 'got expected value set in before');
});
});
});
describe('basic test on beforeEach', () => {
describe('sync test', () => {
let expected: boolean;
beforeEach('init expected value', () => {
expected = true;
});
it('check expected value set in beforeEach', () => {
assert(expected, 'got expected value set in before');
expected = false;
});
it('check expected value set in beforeEach but changed in previous it', () => {
assert(expected, 'got expected value set in before');
});
});
describe('async test', () => {
let expected: boolean;
beforeEach('init expected value', () => {
assert(true, 'got false before wait');
wait<void>(cb => setTimeout(cb, 0));
assert(true, 'got true after wait');
expected = true;
});
it('check expected value set in beforeEach', () => {
assert(expected, 'got expected value set in before');
expected = false;
});
it('check expected value set in beforeEach but changed in previous it', () => {
assert(expected, 'got expected value set in before');
});
});
describe('async test without string prefix', () => {
let expected: boolean;
beforeEach(function () {
this.timeout(20000);
assert(true, 'got false before wait');
wait<void>(cb => setTimeout(cb, 0));
assert(true, 'got true after wait');
expected = true;
});
it('check expected value set in beforeEach', () => {
assert(expected, 'got expected value set in before');
expected = false;
});
it('check expected value set in beforeEach but changed in previous it', () => {
assert(expected, 'got expected value set in before');
});
});
describe('async test with done parameter called too soon', () => {
let expected: boolean;
beforeEach(function (done) {
done();
wait<void>(() =>
setTimeout(() => {
expected = true;
}, 1000),
);
});
it('check expected value set in beforeEach', done => {
assert(!expected, 'got expected value set in before');
done();
});
});
describe('async test with done parameter called in time', () => {
let expected: boolean;
beforeEach(function (done) {
assert(true, 'got true after wait');
setTimeout(() => {
expected = true;
done();
}, 1000);
});
it('check expected value set in beforeEach', () => {
assert(expected, 'got expected value set in before');
});
});
});