|
1 | | -import { isFile, cloneDeep, hasOwnProperty, merge } from '../util' |
| 1 | +import { |
| 2 | + isFile, |
| 3 | + cloneDeep, |
| 4 | + hasOwnProperty, |
| 5 | + merge, |
| 6 | + isPlainObject, |
| 7 | +} from '../util' |
2 | 8 |
|
3 | 9 | describe('Object Test', () => { |
4 | 10 | // const { window, File } = global |
@@ -45,4 +51,26 @@ describe('cloneDeep', () => { |
45 | 51 | const merged = { email: '[email protected]', name: 'Chantouch' } |
46 | 52 | expect(merge(obj1, obj2)).toEqual(merged) |
47 | 53 | }) |
| 54 | + it('should return `true` if the object is created by the `Object` constructor.', () => { |
| 55 | + expect(isPlainObject(Object.create({}))).toBeTruthy() |
| 56 | + expect(isPlainObject(Object.create(Object.prototype))).toBeTruthy() |
| 57 | + expect(isPlainObject({ foo: 'bar' })).toBeTruthy() |
| 58 | + expect(isPlainObject({})).toBeTruthy() |
| 59 | + expect(isPlainObject(Object.create(null))).toBeTruthy() |
| 60 | + }) |
| 61 | + it('should return `false` if the object is not created by the `Object` constructor.', () => { |
| 62 | + function Foo(this: any) { |
| 63 | + this.abc = {} |
| 64 | + } |
| 65 | + expect(isPlainObject(/foo/)).toBeFalsy() |
| 66 | + // eslint-disable-next-line @typescript-eslint/no-empty-function |
| 67 | + expect(isPlainObject(function () {})).toBeFalsy() |
| 68 | + expect(isPlainObject(1)).toBeFalsy() |
| 69 | + expect(isPlainObject(['foo', 'bar'])).toBeFalsy() |
| 70 | + expect(isPlainObject([])).toBeFalsy() |
| 71 | + // eslint-disable-next-line @typescript-eslint/ban-ts-comment |
| 72 | + // @ts-ignore |
| 73 | + expect(isPlainObject(new Foo())).toBeFalsy() |
| 74 | + expect(isPlainObject(null)).toBeFalsy() |
| 75 | + }) |
48 | 76 | }) |
0 commit comments