Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
81155 views
1
/**
2
* Copyright 2013-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').dontMock('keyMirror');
15
16
var keyMirror = require('keyMirror');
17
18
describe('keyMirror', function() {
19
it('should create an object with values matching keys provided', function() {
20
var mirror = keyMirror({
21
foo: null,
22
bar: true,
23
"baz": { some: "object" },
24
qux: undefined
25
});
26
expect('foo' in mirror).toBe(true);
27
expect(mirror.foo).toBe('foo');
28
expect('bar' in mirror).toBe(true);
29
expect(mirror.bar).toBe('bar');
30
expect('baz' in mirror).toBe(true);
31
expect(mirror.baz).toBe('baz');
32
expect('qux' in mirror).toBe(true);
33
expect(mirror.qux).toBe('qux');
34
});
35
36
it('should not use properties from prototypes', function() {
37
function Klass() {
38
this.useMeToo = true;
39
}
40
Klass.prototype.doNotUse = true;
41
var instance = new Klass();
42
instance.useMe = true;
43
44
var mirror = keyMirror(instance);
45
46
expect('doNotUse' in mirror).toBe(false);
47
expect('useMe' in mirror).toBe(true);
48
expect('useMeToo' in mirror).toBe(true);
49
});
50
51
it('should throw when a non-object argument is used', function() {
52
[null, undefined, 0, 7, ['uno'], true, "string"].forEach(function(testVal) {
53
expect(keyMirror.bind(null, testVal)).toThrow();
54
});
55
});
56
57
it('should work when "constructor" is a key', function() {
58
var obj = { constructor: true };
59
expect(keyMirror.bind(null, obj)).not.toThrow();
60
var mirror = keyMirror(obj);
61
expect('constructor' in mirror).toBe(true);
62
});
63
});
64
65
66