react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / utils / __tests__ / accumulateInto-test.js
81155 views/**1* Copyright 2014, Facebook, Inc.2* All rights reserved.3*4* This source code is licensed under the BSD-style license found in the5* LICENSE file in the root directory of this source tree. An additional grant6* of patent rights can be found in the PATENTS file in the same directory.7*8* @emails react-core9*/1011"use strict";1213require('mock-modules')14.dontMock('accumulateInto');1516var accumulateInto;1718describe('accumulateInto', function() {1920beforeEach(function() {21accumulateInto = require('accumulateInto');22});2324it('throws if the second item is null', function() {25expect(function() {26accumulateInto([], null);27}).toThrow(28'Invariant Violation: accumulateInto(...): Accumulated items must not ' +29'be null or undefined.'30);31});3233it('returns the second item if first is null', function() {34var a = [];35expect(accumulateInto(null, a)).toBe(a);36});3738it('merges the second into the first if first item is an array', function() {39var a = [1, 2];40var b = [3, 4];41accumulateInto(a, b);42expect(a).toEqual([1, 2, 3, 4]);43expect(b).toEqual([3, 4]);44var c = [1];45accumulateInto(c, 2);46expect(c).toEqual([1, 2]);47});4849it('returns a new array if first or both items are scalar', function() {50var a = [2];51expect(accumulateInto(1, a)).toEqual([1, 2]);52expect(a).toEqual([2]);53expect(accumulateInto(1, 2)).toEqual([1, 2]);54});55});565758