forked from mcmath/chai-iterator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
iterate-from.js
87 lines (83 loc) · 1.89 KB
/
iterate-from.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
84
85
86
87
const err = require('../helpers/err');
const customIterableFactory = require('../fixtures/custom');
describe('expect/should: iterate.from(iterable)', function () {
context('initial values yielded by target match iterable', function () {
it('passes', function () {
[2, 3, 5].should.iterate.from([2, 3, 5]);
[2, 3, 5].should.iterate.from([2, 3]);
[2, 3, 5].should.iterate.from([]);
'abcdefg'.should.iterate.from('abc');
});
it('throws when negated', function () {
err(function () {
[2, 3, 5].should.not.iterate.from([2, 3, 5]);
});
err(function () {
[2, 3, 5].should.not.iterate.from([2, 3]);
});
err(function () {
[2, 3, 5].should.not.iterate.from([]);
});
err(function () {
'abcdefg'.should.not.iterate.from('abc');
});
});
});
context('initial values yielded by target do not match iterable', function () {
it('throws', function () {
err(function () {
[2, 3, 5].should.iterate.from([3, 5]);
});
});
it('passes when negated', function () {
[2, 3, 5].should.not.iterate.from([3, 5]);
});
});
context('deep flag is set', function () {
it('uses deep equality to compare values', function () {
[
{
id: 2
},
{
id: 3
}
].should.deep.iterate.from([
{
id: 2
}
]);
[
{
id: 2
},
{
id: 3
}
].should.not.iterate.from([
{
id: 2
}
]);
});
});
context('iterate flag is not set', function () {
it('throws whether negated or not', function () {
err(function () {
[2, 3, 5].should.from([2, 3]);
});
err(function () {
[2, 3, 5].should.not.from([3, 5]);
});
});
});
});
context('iterator ed by @@iterator is not itself iterable', function () {
it('works correctly', function () {
const iterable = customIterableFactory();
err(function () {
iterable.should.iterate.from([2, 3]);
});
iterable.should.iterate.from([0, 1]);
});
});