Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81155 views
1
/**
2
* Copyright 2014, Facebook, Inc.
3
* All rights reserved.
4
*
5
* This source code is licensed under the BSD-style license found in the
6
* LICENSE file in the root directory of this source tree. An additional grant
7
* of patent rights can be found in the PATENTS file in the same directory.
8
*
9
* @emails react-core
10
*/
11
12
"use strict";
13
14
require('mock-modules')
15
.dontMock('accumulateInto');
16
17
var accumulateInto;
18
19
describe('accumulateInto', function() {
20
21
beforeEach(function() {
22
accumulateInto = require('accumulateInto');
23
});
24
25
it('throws if the second item is null', function() {
26
expect(function() {
27
accumulateInto([], null);
28
}).toThrow(
29
'Invariant Violation: accumulateInto(...): Accumulated items must not ' +
30
'be null or undefined.'
31
);
32
});
33
34
it('returns the second item if first is null', function() {
35
var a = [];
36
expect(accumulateInto(null, a)).toBe(a);
37
});
38
39
it('merges the second into the first if first item is an array', function() {
40
var a = [1, 2];
41
var b = [3, 4];
42
accumulateInto(a, b);
43
expect(a).toEqual([1, 2, 3, 4]);
44
expect(b).toEqual([3, 4]);
45
var c = [1];
46
accumulateInto(c, 2);
47
expect(c).toEqual([1, 2]);
48
});
49
50
it('returns a new array if first or both items are scalar', function() {
51
var a = [2];
52
expect(accumulateInto(1, a)).toEqual([1, 2]);
53
expect(a).toEqual([2]);
54
expect(accumulateInto(1, 2)).toEqual([1, 2]);
55
});
56
});
57
58