forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbind.spec.js
More file actions
62 lines (51 loc) · 1.63 KB
/
bind.spec.js
File metadata and controls
62 lines (51 loc) · 1.63 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
51
52
53
54
55
56
57
58
59
60
61
62
import expect from 'expect';
import {
Validator as ValidatorProblem,
} from './problem';
import { Validator } from './bind';
import {
Validator as ValidatorArrow,
} from './constructorArrow';
import {
Validator as ValidatorConstructor,
} from './constructor';
import {
Validator as ValidatorProperties,
} from './properties';
describe('Validator', () => {
it('should not bind to this', () => {
try {
// START: problem
const validator = new ValidatorProblem();
validator.setInvalidMessages('city');
// TypeError: Cannot read property 'message' of undefined
// END: problem
} catch (e) {
expect(e.message).toEqual("Cannot read property 'message' of undefined");
}
});
it('should bind methods in map function', () => {
const v = new Validator();
const message = 'city is invalid.';
expect(v.setInvalidMessages('city')).toEqual([message]);
});
it('should use arrow methods in constructor', () => {
const v = new ValidatorArrow();
const message = 'city is invalid.';
expect(v.setInvalidMessages('city')).toEqual([message]);
});
it('should bind methods in constructor', () => {
const v = new ValidatorConstructor();
const message = 'city is invalid.';
expect(v.setInvalidMessages('city')).toEqual([message]);
});
it('should have private properties', () => {
const v = new ValidatorProperties();
expect(v.message).toEqual('is invalid.');
});
it('should bind this with arrow functions', () => {
const v = new ValidatorProperties();
const message = 'city is invalid.';
expect(v.setInvalidMessages('city')).toEqual([message]);
});
});