UNPKG

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