-
Notifications
You must be signed in to change notification settings - Fork 5
/
iterationDecorator-test.js
61 lines (60 loc) · 2.17 KB
/
iterationDecorator-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
56
57
58
59
60
61
/* eslint-env mocha */
import expect from 'expect';
import iterationDecorator from '../../../src/util/iterationDecorator';
describe('iterationDecorator', function () {
describe('should add a Symbol.iterator property to a collection', function () {
it('should return the values when iterated', function () {
// const collection = {a: 'apple', b: 'banana', c: 'cantaloupe'};
const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const arr = ['apple', 'banana', 'cantaloupe'];
const iter = iterationDecorator(collection, Object.values(collection));
expect([...iter]).toEqual(expect.arrayContaining(arr));
});
});
describe('when Symbol is not defined in the global space', function () {
beforeEach(function () {
global.originalSymbol = global.Symbol
global.originalSymbolIterator = global.Symbol.iterator;
global.Symbol = undefined;
});
it('should not add a Symbol.iterator property to a collection', function () {
const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const iter = iterationDecorator(collection, []);
expect(iter[global.originalSymbolIterator]).not.toBeDefined();
});
afterEach(function () {
global.Symbol = global.originalSymbol;
global.originalSymbol = undefined;
global.originalSymbolIterator = undefined;
});
});
describe('when Symbol.iterator is not defined in the global space', function () {
beforeEach(function () {
global.originalSymbol = global.Symbol
global.originalSymbolIterator = global.Symbol.iterator;
global.Symbol = function () {};
});
it('should not add a Symbol.iterator property to a collection', function () {
const collection = {
'a': 'apple',
'b': 'banana',
'c': 'cantaloupe',
};
const iter = iterationDecorator(collection, []);
expect(iter[global.originalSymbolIterator]).not.toBeDefined();
});
afterEach(function () {
global.Symbol = global.originalSymbol;
global.originalSymbol = undefined;
global.originalSymbolIterator = undefined;
});
});
});