1 |
|
2 |
|
3 |
|
4 | var helper = require('../lib/helper')
|
5 | ;
|
6 |
|
7 | require('chai').should();
|
8 |
|
9 | describe('helper.moosh()', function() {
|
10 | it('should return the second if the first is undefined', function() {
|
11 | helper.moosh(undefined, 'text').should.equal('text');
|
12 | helper.moosh(undefined, [ 'item', 'item2' ]).should.deep.equal([ 'item', 'item2' ]);
|
13 | });
|
14 |
|
15 | it('should return size-two arrays on non-array inputs', function() {
|
16 | helper.moosh('item1', 'item2').should.deep.equal([ 'item1', 'item2' ]);
|
17 | helper.moosh('item1', null).should.deep.equal([ 'item1', null ]);
|
18 | helper.moosh('item1', 0).should.deep.equal([ 'item1', 0 ]);
|
19 | helper.moosh('item1', {}).should.deep.equal([ 'item1', {}]);
|
20 | helper.moosh({}, {}).should.deep.equal([{}, {}]);
|
21 | });
|
22 |
|
23 | it('should unwrap single-element arrays', function() {
|
24 | helper.moosh(undefined, [ 'item' ]).should.equal('item');
|
25 | helper.moosh([ 'item' ], undefined).should.equal('item');
|
26 | helper.moosh([ 'item' ], [ 'item2' ]).should.deep.equal([ 'item', 'item2' ]);
|
27 | });
|
28 |
|
29 | it('should preserve arrays when asked', function() {
|
30 | helper.moosh(undefined, [ 'item' ], true).should.deep.equal([ 'item' ]);
|
31 | helper.moosh([ 'item' ], undefined, true).should.deep.equal([ 'item' ]);
|
32 | helper.moosh('item', undefined, true).should.deep.equal([ 'item' ]);
|
33 | helper.moosh(undefined, 'item', true).should.deep.equal([ 'item' ]);
|
34 | });
|
35 |
|
36 | it('should concatenate arrays', function() {
|
37 | helper.moosh([ 'item1', 'item2' ], [ 'item3' ]).should.deep.equal([ 'item1', 'item2', 'item3' ]);
|
38 | helper.moosh([ 'item1' ], [ 'item2', 'item3' ]).should.deep.equal([ 'item1', 'item2', 'item3' ]);
|
39 | helper.moosh([ 'item1', 'item2' ], [ 'item3', 'item4' ]).should.deep.equal([ 'item1', 'item2', 'item3', 'item4' ]);
|
40 | helper.moosh([ 'item1', 'item2' ], 'item3').should.deep.equal([ 'item1', 'item2', 'item3' ]);
|
41 | helper.moosh('item1', [ 'item2', 'item3' ]).should.deep.equal([ 'item1', 'item2', 'item3' ]);
|
42 | });
|
43 | });
|