Add test for elements in isPlainObject and fix up check

This commit is contained in:
Phil Pluckthun
2021-01-08 15:09:38 +00:00
parent 5fcbc778a9
commit 5cf1111981
2 changed files with 5 additions and 1 deletions

View File

@@ -5,4 +5,4 @@ export default (x: any): boolean =>
typeof x === 'object' &&
(x.toString ? x.toString() : Object.prototype.toString.call(x)) === '[object Object]' &&
/* check for reasonable markers that the object isn't an element for react & preact/compat */
!(x.$$typeof && (x._owner || (x.__v && x.__o)));
!(x.$$typeof && ('_owner' in x) || x.__v);

View File

@@ -29,6 +29,10 @@ it('returns false for a React component', () => {
expect(isPlainObject(Foo)).toEqual(false);
});
it('returns false for a React element', () => {
expect(isPlainObject(React.createElement('div'))).toEqual(false);
});
it('returns true for an object literal created in a different context', () => {
const context = vm.createContext({});
vm.runInContext('object = {};', context);