1
- /* eslint-env mocha */
2
- import expect from 'expect' ;
1
+ import test from 'tape' ;
2
+ import values from 'object.values' ;
3
+ import mockProperty from 'mock-property' ;
4
+
3
5
import iterationDecorator from '../../../src/util/iterationDecorator' ;
4
6
5
- describe ( 'iterationDecorator' , function ( ) {
6
- describe ( 'should add a Symbol.iterator property to a collection' , function ( ) {
7
- it ( 'should return the values when iterated' , function ( ) {
7
+ test ( 'iterationDecorator' , ( t ) => {
8
+ t . test ( 'adds a Symbol.iterator property to a collection' , async ( st ) => {
8
9
// const collection = {a: 'apple', b: 'banana', c: 'cantaloupe'};
9
10
const collection = {
10
11
'a' : 'apple' ,
11
12
'b' : 'banana' ,
12
13
'c' : 'cantaloupe' ,
13
14
} ;
14
15
const arr = [ 'apple' , 'banana' , 'cantaloupe' ] ;
15
- const iter = iterationDecorator ( collection , Object . values ( collection ) ) ;
16
- expect ( [ ...iter ] ) . toEqual ( expect . arrayContaining ( arr ) ) ;
17
- } ) ;
16
+ const iter = iterationDecorator ( collection , values ( collection ) ) ;
17
+ st . deepEqual ( [ ...iter ] , arr , 'returns the values when iterated' ) ;
18
18
} ) ;
19
- describe ( 'when Symbol is not defined in the global space' , function ( ) {
20
- beforeEach ( function ( ) {
21
- global . originalSymbol = global . Symbol
22
- global . originalSymbolIterator = global . Symbol . iterator ;
23
- global . Symbol = undefined ;
24
- } ) ;
25
- it ( 'should not add a Symbol.iterator property to a collection' , function ( ) {
26
- const collection = {
27
- 'a' : 'apple' ,
28
- 'b' : 'banana' ,
29
- 'c' : 'cantaloupe' ,
30
- } ;
31
- const iter = iterationDecorator ( collection , [ ] ) ;
32
- expect ( iter [ global . originalSymbolIterator ] ) . not . toBeDefined ( ) ;
33
- } ) ;
34
- afterEach ( function ( ) {
35
- global . Symbol = global . originalSymbol ;
36
- global . originalSymbol = undefined ;
37
- global . originalSymbolIterator = undefined ;
38
- } ) ;
19
+
20
+ t . test ( 'when Symbol is not defined in the global space' , async ( st ) => {
21
+ const originalSymbolIterator = typeof Symbol === 'function' ? Symbol . iterator : null ;
22
+ st . teardown ( mockProperty ( global , 'Symbol' , { value : undefined } ) ) ;
23
+
24
+ const collection = {
25
+ 'a' : 'apple' ,
26
+ 'b' : 'banana' ,
27
+ 'c' : 'cantaloupe' ,
28
+ } ;
29
+ const iter = iterationDecorator ( collection , [ ] ) ;
30
+ st . equal ( iter [ originalSymbolIterator ] , undefined , 'does not add a Symbol.iterator property to a collection' ) ;
39
31
} ) ;
40
- describe ( 'when Symbol.iterator is not defined in the global space' , function ( ) {
41
- beforeEach ( function ( ) {
42
- global . originalSymbol = global . Symbol
43
- global . originalSymbolIterator = global . Symbol . iterator ;
44
- global . Symbol = function ( ) { } ;
45
- } ) ;
46
- it ( 'should not add a Symbol.iterator property to a collection' , function ( ) {
47
- const collection = {
48
- 'a' : 'apple' ,
49
- 'b' : 'banana' ,
50
- 'c' : 'cantaloupe' ,
51
- } ;
52
- const iter = iterationDecorator ( collection , [ ] ) ;
53
- expect ( iter [ global . originalSymbolIterator ] ) . not . toBeDefined ( ) ;
54
- } ) ;
55
- afterEach ( function ( ) {
56
- global . Symbol = global . originalSymbol ;
57
- global . originalSymbol = undefined ;
58
- global . originalSymbolIterator = undefined ;
59
- } ) ;
32
+
33
+ t . test ( 'when Symbol.iterator is not defined in the global space' , async ( st ) => {
34
+ const originalSymbolIterator = typeof Symbol === 'function' ? Symbol . iterator : null ;
35
+ st . teardown ( mockProperty ( global , 'Symbol' , { value : function ( ) { } } ) ) ;
36
+
37
+ const collection = {
38
+ 'a' : 'apple' ,
39
+ 'b' : 'banana' ,
40
+ 'c' : 'cantaloupe' ,
41
+ } ;
42
+ const iter = iterationDecorator ( collection , [ ] ) ;
43
+ st . equal ( iter [ originalSymbolIterator ] , undefined , 'does not add a Symbol.iterator property to a collection' ) ;
60
44
} ) ;
61
45
} ) ;
0 commit comments