1 | import { isPlainObject } from '@reduxjs/toolkit'
|
2 | import vm from 'vm'
|
3 |
|
4 | describe('isPlainObject', () => {
|
5 | it('returns true only if plain object', () => {
|
6 | class Test {
|
7 | prop: number
|
8 | constructor() {
|
9 | this.prop = 1
|
10 | }
|
11 | }
|
12 |
|
13 | const sandbox = { fromAnotherRealm: false }
|
14 | vm.runInNewContext('fromAnotherRealm = {}', sandbox)
|
15 |
|
16 | expect(isPlainObject(sandbox.fromAnotherRealm)).toBe(true)
|
17 | expect(isPlainObject(new Test())).toBe(false)
|
18 | expect(isPlainObject(new Date())).toBe(false)
|
19 | expect(isPlainObject([1, 2, 3])).toBe(false)
|
20 | expect(isPlainObject(null)).toBe(false)
|
21 | expect(isPlainObject(undefined)).toBe(false)
|
22 | expect(isPlainObject({ x: 1, y: 2 })).toBe(true)
|
23 | })
|
24 | })
|