react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / addons / __tests__ / update-test.js
81155 views/**1* Copyright 2013-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";1213var update = require('update');1415describe('update', function() {16it('should support push', function() {17expect(update([1], {$push: [7]})).toEqual([1, 7]);18expect(update.bind(null, [], {$push: 7})).toThrow(19'Invariant Violation: update(): expected spec of $push to be an ' +20'array; got 7. Did you forget to wrap your parameter in an array?'21);22expect(update.bind(null, 1, {$push: 7})).toThrow(23'Invariant Violation: update(): expected target of $push to be an ' +24'array; got 1.'25);26});2728it('should support unshift', function() {29expect(update([1], {$unshift: [7]})).toEqual([7, 1]);30expect(update.bind(null, [], {$unshift: 7})).toThrow(31'Invariant Violation: update(): expected spec of $unshift to be an ' +32'array; got 7. Did you forget to wrap your parameter in an array?'33);34expect(update.bind(null, 1, {$unshift: 7})).toThrow(35'Invariant Violation: update(): expected target of $unshift to be an ' +36'array; got 1.'37);38});3940it('should support splice', function() {41expect(update([1, 4, 3], {$splice: [[1, 1, 2]]})).toEqual([1, 2, 3]);42expect(update.bind(null, [], {$splice: 1})).toThrow(43'Invariant Violation: update(): expected spec of $splice to be an ' +44'array of arrays; got 1. Did you forget to wrap your parameters in an '+45'array?'46);47expect(update.bind(null, [], {$splice: [1]})).toThrow(48'Invariant Violation: update(): expected spec of $splice to be an ' +49'array of arrays; got 1. Did you forget to wrap your parameters in an ' +50'array?'51);52expect(update.bind(null, 1, {$splice: 7})).toThrow(53'Invariant Violation: Expected $splice target to be an array; got 1'54);55});5657it('should support merge', function() {58expect(update({a: 'b'}, {$merge: {c: 'd'}})).toEqual({a: 'b', c: 'd'});59expect(update.bind(null, {}, {$merge: 7})).toThrow(60'Invariant Violation: update(): $merge expects a spec of type ' +61'\'object\'; got 7'62);63expect(update.bind(null, 7, {$merge: {a: 'b'}})).toThrow(64'Invariant Violation: update(): $merge expects a target of type ' +65'\'object\'; got 7'66);67});6869it('should support set', function() {70expect(update({a: 'b'}, {$set: {c: 'd'}})).toEqual({c: 'd'});71});7273it('should support apply', function() {74expect(update(2, {$apply: function(x) { return x * 2; }})).toEqual(4);75expect(update.bind(null, 2, {$apply: 123})).toThrow(76'Invariant Violation: update(): expected spec of $apply to be a ' +77'function; got 123.'78);79});8081it('should support deep updates', function() {82expect(update({a: 'b', c: {d: 'e'}}, {c: {d: {$set: 'f'}}})).toEqual({83a: 'b',84c: {d: 'f'}85});86});8788it('should require a command', function() {89expect(update.bind(null, {a: 'b'}, {a: 'c'})).toThrow(90'Invariant Violation: update(): You provided a key path to update() ' +91'that did not contain one of $push, $unshift, $splice, $set, $merge, ' +92'$apply. Did you forget to include {$set: ...}?'93);94});95});969798