-
-
Notifications
You must be signed in to change notification settings - Fork 85
/
spec.js
83 lines (69 loc) · 1.87 KB
/
spec.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
74
75
76
77
78
79
80
81
82
83
import VestTest from '.';
const suiteId = 'validation-suite';
const fieldName = 'unicycle';
const statement = 'I am Root.';
describe('VestTest', () => {
let testObject;
beforeEach(() => {
testObject = new VestTest({
fieldName,
statement,
suiteId,
testFn: jest.fn(),
});
});
test('TestObject constructor', () => {
expect(testObject).toMatchSnapshot();
});
it('Should have a unique id', () => {
Array.from(
{ length: 100 },
() => new VestTest({ fieldName, statement, suiteId, testFn: jest.fn() })
).reduce((existing, { id }) => {
expect(existing[id]).toBeUndefined();
existing[id] = true;
return existing;
}, {});
});
describe('testObject.warn', () => {
it('Should return current instance', () => {
expect(testObject.warn()).toBe(testObject);
});
it('Should set `.isWarning` to true', () => {
expect(testObject.isWarning).toBe(false);
testObject.warn();
expect(testObject.isWarning).toBe(true);
expect(testObject).toMatchSnapshot();
});
});
describe('testObject.fail', () => {
beforeEach(() => {
jest.resetModules();
const VestTest = require('.');
testObject = new VestTest({
fieldName,
statement,
suiteId,
testFn: jest.fn(),
});
});
afterEach(() => {
jest.resetAllMocks();
});
it('Should set this.failed to true', () => {
expect(testObject.failed).toBe(false);
testObject.fail();
expect(testObject.failed).toBe(true);
});
});
describe('testobject.valueOf', () => {
test('When `failed` is false', () => {
expect(testObject.failed).toBe(false);
expect(testObject.valueOf()).toBe(true);
});
test('When `failed` is true', () => {
testObject.failed = true;
expect(testObject.valueOf()).toBe(false);
});
});
});