-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-api.js
73 lines (61 loc) · 1.61 KB
/
test-api.js
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
/**
* @fileinfo
*
* Import from this file into your unit tests themselves. It's a pure ES6 module
* capable of running in modern web browsers without transpilation.
*
* For the test runner API that runs in Node, see index.js.
*/
import _assert from "./src/assert.js";
export const assert = _assert;
const api = window['__esmunit__api__'];
if (!api) {
throw new Error("ESM Unit test runner not loaded");
}
const describeTestSuite = api['describeTestSuite'];
const addTest = api['addTest'];
const addLifecycleFunction = api['addLifecycleFunction'];
const runRootTestSuite = api['runRootTestSuite'];
/**
* @param {!string} suiteName The name of your test suite
* @param {!function} suiteFunc A function that, when run, defines your test suite
*/
export function describe(suiteName, suiteFunc) {
if (typeof suiteName !== "string" || !suiteName) {
throw new TypeError("Suite name is required");
}
describeTestSuite(suiteName, suiteFunc);
}
export function test(testName, func) {
if (typeof testName !== "string" || !testName) {
throw new TypeError("Test name is required");
}
addTest(testName, func);
}
/**
* @param {!function} func
*/
export function before(func) {
addLifecycleFunction("before", func);
}
/**
* @param {!function} func
*/
export function beforeEach(func) {
addLifecycleFunction("beforeEach", func);
}
/**
* @param {!function} func
*/
export function after(func) {
addLifecycleFunction("after", func);
}
/**
* @param {!function} func
*/
export function afterEach(func) {
addLifecycleFunction("afterEach", func);
}
export function runTests() {
return runRootTestSuite();
}