mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
feat(store): add reactive state primitives (#311)
This commit is contained in:
@@ -8,6 +8,7 @@ import {
|
||||
isNull,
|
||||
isNumber,
|
||||
isObject,
|
||||
isPlainObject,
|
||||
isPromise,
|
||||
isString,
|
||||
isUndefined,
|
||||
@@ -175,6 +176,44 @@ describe('predicate', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('isPlainObject', () => {
|
||||
it('returns true for plain objects', () => {
|
||||
expect(isPlainObject({})).toBe(true);
|
||||
expect(isPlainObject({ a: 1 })).toBe(true);
|
||||
expect(isPlainObject(Object.create(null))).toBe(true);
|
||||
expect(isPlainObject(new Object())).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for arrays', () => {
|
||||
expect(isPlainObject([])).toBe(false);
|
||||
expect(isPlainObject([1, 2, 3])).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for class instances', () => {
|
||||
class Foo {}
|
||||
expect(isPlainObject(new Foo())).toBe(false);
|
||||
expect(isPlainObject(new Date())).toBe(false);
|
||||
expect(isPlainObject(new Map())).toBe(false);
|
||||
expect(isPlainObject(new Set())).toBe(false);
|
||||
expect(isPlainObject(/regex/)).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for primitives', () => {
|
||||
expect(isPlainObject(null)).toBe(false);
|
||||
expect(isPlainObject(undefined)).toBe(false);
|
||||
expect(isPlainObject('string')).toBe(false);
|
||||
expect(isPlainObject(123)).toBe(false);
|
||||
expect(isPlainObject(true)).toBe(false);
|
||||
// eslint-disable-next-line symbol-description
|
||||
expect(isPlainObject(Symbol())).toBe(false);
|
||||
});
|
||||
|
||||
it('returns false for functions', () => {
|
||||
expect(isPlainObject(() => {})).toBe(false);
|
||||
expect(isPlainObject(() => {})).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isAbortError', () => {
|
||||
it('returns true for AbortError', () => {
|
||||
const error = new DOMException('Aborted', 'AbortError');
|
||||
|
||||
Reference in New Issue
Block a user