-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.jsx
102 lines (92 loc) · 2.37 KB
/
index.jsx
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
/* globals jsdom */
import React from 'react';
/**
* Simple wrapper around mocha describe which allows a boolean to be passed in first which
* determines whether or not the test will be run
*/
export function describeIf(test, a, b) {
if (test) {
describe(a, b);
} else {
describe.skip(a, b);
}
}
/**
* Simple wrapper around mocha it which allows a boolean to be passed in first which
* determines whether or not the test will be run
*/
export function itIf(test, a, b) {
if (test) {
it(a, b);
} else {
it.skip(a, b);
}
}
/**
* Simple wrapper around mocha it which allows an array of possible values to test against.
* Each test will be wrapped in a try/catch block to handle any errors.
*
* @param {Object[]} data
* @param {String} message
* @param {Function} factory
*/
export function itWithData(data, message, factory) {
data.forEach((testCase) => {
it(`${message} ${testCase.message}`, () => factory(testCase));
});
}
function only(a, b) {
describe('(uses jsdom)', () => {
if (typeof jsdom === 'function') {
jsdom();
describe.only(a, b);
} else {
// if jsdom isn't available, skip every test in this describe context
describe.skip(a, b);
}
});
}
function skip(a, b) {
describe('(uses jsdom)', () => {
if (typeof jsdom === 'function') {
jsdom();
describe.skip(a, b);
} else {
// if jsdom isn't available, skip every test in this describe context
describe.skip(a, b);
}
});
}
export function describeWithDOM(a, b) {
describe('(uses jsdom)', () => {
if (global.document) {
describe(a, b);
} else {
// if jsdom isn't available, skip every test in this describe context
describe.skip(a, b);
}
});
}
describeWithDOM.only = only;
describeWithDOM.skip = skip;
/**
* React component used for testing.
*/
class TestHelper extends React.Component {
render() {
return <div />;
}
}
/**
* Possible values for React render() checks.
*/
export function generateEmptyRenderData() {
return [
// Returns true for empty
{ message: 'false', value: false, expectResponse: true },
{ message: 'null', value: null, expectResponse: true },
// Returns false for empty, valid returns
{ message: 'React component', value: <TestHelper />, expectResponse: false },
{ message: 'React element', value: <span />, expectResponse: false },
];
}