forked from gmmorris/simmerjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.test.js
55 lines (45 loc) · 1.53 KB
/
parser.test.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
import Parser from './parser'
describe('Parser', () => {
describe('next', () => {
test(`calls the next function in the queue with the supplied arguments`, function () {
const returnValue = { some: 0 }
const method = jest.fn(() => returnValue)
const parser = new Parser({
getMethods: () => [method]
})
expect(parser.next(1, 2, 3)).toBe(returnValue)
expect(method.mock.calls[0]).toMatchObject([1, 2, 3])
})
test(`removes the called method`, function () {
const first = jest.fn(val => val)
const second = jest.fn(val => val)
const parser = new Parser({
getMethods: () => [first, second]
})
expect(parser.next(1, 2, 3, 4, 5, 6)).toBe(1)
expect(parser.next(6, 5, 4, 3, 2, 1)).toBe(6)
expect(second.mock.calls[0]).toMatchObject([6, 5, 4, 3, 2, 1])
})
test(`returns false if no more methods are left`, function () {
const parser = new Parser({
getMethods: () => [val => val]
})
parser.next(1, 2, 3, 4, 5, 6)
expect(parser.next(6, 5, 4, 3, 2, 1)).toBe(false)
})
})
describe('finish', () => {
test(`returns true if no methods are left in the queue`, function () {
const parser = new Parser({
getMethods: () => []
})
expect(parser.finished()).toBe(true)
})
test(`returns false if there are methods left in the queue`, function () {
const parser = new Parser({
getMethods: () => [() => 123]
})
expect(parser.finished()).toBe(false)
})
})
})