forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrest.spec.js
More file actions
61 lines (57 loc) · 2.1 KB
/
Copy pathrest.spec.js
File metadata and controls
61 lines (57 loc) · 2.1 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
import expect from 'expect';
import {
validateCharacterCount as validateSimple,
} from './simple';
import {
getArguments as getArgumentsProblem,
validateCharacterCount as validateProblem,
} from './problem';
import {
getArguments,
shift,
validateCharacterCount,
} from './rest';
describe('validate character simple', () => {
it('should be correct when passed an array', () => {
expect(validateSimple(5, ['red', 'blue'])).toEqual(true);
expect(validateSimple(5, ['red', 'blue', 'yellow'])).toEqual(false);
});
it('should be incorrect when passed a list', () => {
try {
validateSimple(5, 'red', 'blue');
} catch (e) {
expect(e instanceof TypeError).toBe(true);
expect(e.message).toEqual('items.every is not a function');
}
});
});
describe('validate character problem', () => {
it('should check all characters are below limit', () => {
expect(validateProblem(5, 'red', 'blue')).toEqual(true);
expect(validateProblem(5, 'red', 'blue', 'yellow')).toEqual(false);
});
it('should is incorrect when passed an array', () => {
expect(validateProblem(5, ['red', 'blue'])).toEqual(true);
expect(validateProblem(5, ['red', 'blue', 'yellow'])).toEqual(true);
});
it('should get arguments', () => {
expect(getArgumentsProblem('Bloomsday', 'June 16')[0]).toBe('Bloomsday');
expect(getArgumentsProblem('Bloomsday', 'June 16')[1]).toBe('June 16');
});
});
describe('validate character problem', () => {
it('should check all characters are below limit', () => {
expect(validateCharacterCount(5, 'red', 'blue')).toEqual(true);
expect(validateCharacterCount(5, 'red', 'blue', 'yellow')).toEqual(false);
});
it('should be correct when passed an array with spread', () => {
expect(validateProblem(5, ...['red', 'blue'])).toEqual(true);
expect(validateProblem(5, ...['red', 'blue', 'yellow'])).toEqual(false);
});
it('should get arguments', () => {
expect(getArguments('Bloomsday', 'June 16')).toEqual(['Bloomsday', 'June 16']);
});
it('should shift array', () => {
expect(shift()).toEqual(['stop', ['collaborate', 'listen']]);
});
});