react / react-0.13.3 / examples / basic-commonjs / node_modules / reactify / node_modules / react-tools / src / utils / __tests__ / keyMirror-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";1213require('mock-modules').dontMock('keyMirror');1415var keyMirror = require('keyMirror');1617describe('keyMirror', function() {18it('should create an object with values matching keys provided', function() {19var mirror = keyMirror({20foo: null,21bar: true,22"baz": { some: "object" },23qux: undefined24});25expect('foo' in mirror).toBe(true);26expect(mirror.foo).toBe('foo');27expect('bar' in mirror).toBe(true);28expect(mirror.bar).toBe('bar');29expect('baz' in mirror).toBe(true);30expect(mirror.baz).toBe('baz');31expect('qux' in mirror).toBe(true);32expect(mirror.qux).toBe('qux');33});3435it('should not use properties from prototypes', function() {36function Klass() {37this.useMeToo = true;38}39Klass.prototype.doNotUse = true;40var instance = new Klass();41instance.useMe = true;4243var mirror = keyMirror(instance);4445expect('doNotUse' in mirror).toBe(false);46expect('useMe' in mirror).toBe(true);47expect('useMeToo' in mirror).toBe(true);48});4950it('should throw when a non-object argument is used', function() {51[null, undefined, 0, 7, ['uno'], true, "string"].forEach(function(testVal) {52expect(keyMirror.bind(null, testVal)).toThrow();53});54});5556it('should work when "constructor" is a key', function() {57var obj = { constructor: true };58expect(keyMirror.bind(null, obj)).not.toThrow();59var mirror = keyMirror(obj);60expect('constructor' in mirror).toBe(true);61});62});63646566