@qntm-code/utils
Version:
A collection of useful utility functions with associated TypeScript types. All functions have been unit tested.
27 lines (26 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const isPlainObject_1 = require("./isPlainObject");
describe(`isPlainObject`, () => {
it('should return `true` if the object is created by the `Object` constructor.', () => {
expect((0, isPlainObject_1.isPlainObject)(Object.create({}))).toBeTrue();
expect((0, isPlainObject_1.isPlainObject)(Object.create(Object.prototype))).toBeTrue();
expect((0, isPlainObject_1.isPlainObject)({ foo: 'bar' })).toBeTrue();
expect((0, isPlainObject_1.isPlainObject)({})).toBeTrue();
expect((0, isPlainObject_1.isPlainObject)(Object.create(null))).toBeTrue();
});
it('should return `false` if the object is not created by the `Object` constructor.', () => {
function Foo() {
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
this.abc = {};
}
expect((0, isPlainObject_1.isPlainObject)(/foo/)).toBeFalse();
// eslint-disable-next-line @typescript-eslint/no-empty-function
expect((0, isPlainObject_1.isPlainObject)(function () { })).toBeFalse();
expect((0, isPlainObject_1.isPlainObject)(1)).toBeFalse();
expect((0, isPlainObject_1.isPlainObject)(['foo', 'bar'])).toBeFalse();
expect((0, isPlainObject_1.isPlainObject)([])).toBeFalse();
expect((0, isPlainObject_1.isPlainObject)(new Foo())).toBeFalse();
expect((0, isPlainObject_1.isPlainObject)(null)).toBeFalse();
});
});