/
utils.js
62 lines (59 loc) · 1.81 KB
/
utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @jest-environment jsdom
*/
/* global document */
// eslint-disable-next-line import/no-unresolved -- immutable is resolve by jest resolver
import { List, isPlainObject } from 'immutable';
describe('Utils', () => {
describe('isPlainObj()', function testFunc() {
const nonPlainCases = [
['Host object', document.createElement('div')],
['bool primitive false', false],
['bool primitive true', true],
['falsy undefined', undefined],
['falsy null', null],
['Simple function', function () {}],
[
'Instance of other object',
(function () {
function Foo() {}
return new Foo();
})(),
],
['Number primitive ', 5],
['String primitive ', 'P'],
['Number Object', Number(6)],
['Immutable.List', new List()],
['simple array', ['one']],
['Error', Error],
['Internal namespaces', Math],
['Arguments', arguments],
];
const plainCases = [
['literal Object', {}],
['new Object', new Object()], // eslint-disable-line no-new-object
['Object.create(null)', Object.create(null)],
['nested object', { one: { prop: 'two' } }],
['constructor prop', { constructor: 'prop' }], // shadows an object's constructor
['constructor.name', { constructor: { name: 'two' } }], // shadows an object's constructor.name
[
'Fake toString',
{
toString: function () {
return '[object Object]';
},
},
],
];
nonPlainCases.forEach(([name, value]) => {
it(`${name} returns false`, () => {
expect(isPlainObject(value)).toBe(false);
});
});
plainCases.forEach(([name, value]) => {
it(`${name} returns true`, () => {
expect(isPlainObject(value)).toBe(true);
});
});
});
});