forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.spec.js
More file actions
50 lines (42 loc) · 1.3 KB
/
context.spec.js
File metadata and controls
50 lines (42 loc) · 1.3 KB
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
import expect from 'expect';
import { validator } from './context';
import {
validator as validatorBasic,
} from './basic';
import {
validator as validatorProblem,
} from './problem';
import {
validator as validatorMethod,
} from './method';
describe('validation', () => {
const field = 'city';
it('should set invalid message', () => {
const message = 'city is invalid.';
expect(validatorBasic.setInvalidMessage(field)).toEqual(message);
});
it('should not access context on map function', () => {
try {
// START: problem
validatorProblem.setInvalidMessages(field);
// TypeError: Cannot read property 'message' of undefined
// END: problem
} catch (e) {
expect(e.message).toEqual("Cannot read property 'message' of undefined");
}
});
it('should access context with arrow function', () => {
const messages = ['city is invalid.'];
expect(validator.setInvalidMessages(field)).toEqual(messages);
});
it('should not access context on map function', () => {
try {
// START: problemMethod
validatorMethod.setInvalidMessage(field);
// TypeError: Cannot read property 'message' of undefined
// END: problemMethod
} catch (e) {
expect(e.message).toEqual("Cannot read property 'message' of undefined");
}
});
});