test: Add test coverage

This commit is contained in:
raon0211 2024-08-09 10:53:56 +09:00
parent 0eab4b9c9c
commit 089d2a0fff
5 changed files with 57 additions and 12 deletions

View File

@ -1,7 +1,7 @@
import { describe, expect, it } from 'vitest'; import { describe, expect, it } from 'vitest';
import { size } from '../../index';
import { falsey } from '../_internal/falsey'; import { falsey } from '../_internal/falsey';
import { toArgs } from '../_internal/toArgs'; import { toArgs } from '../_internal/toArgs';
import { size } from './size';
const args = toArgs([1, 2, 3]); const args = toArgs([1, 2, 3]);
/** /**

View File

@ -29,12 +29,4 @@ describe('padStart', () => {
it('should not pad a string if the length is negative', () => { it('should not pad a string if the length is negative', () => {
expect(padStart('abc', -3)).toBe('abc'); expect(padStart('abc', -3)).toBe('abc');
}); });
it('should not pad a string if the length is Infinity', () => {
expect(padStart('abc', Infinity)).toBe('abc');
});
it('should not pad a string if the length is -Infinity', () => {
expect(padStart('abc', -Infinity)).toBe('abc');
});
}); });

View File

@ -26,6 +26,14 @@ describe('cloneDeep', () => {
expect(clonedArr).not.toBe(arr); expect(clonedArr).not.toBe(arr);
}); });
it('should clone RegExp arrays', () => {
const arr = /test/.exec('hello test');
const cloned = cloneDeep(arr);
expect(cloned).toEqual(arr);
expect(cloned).not.toBe(arr);
})
it('should clone arrays with nested objects', () => { it('should clone arrays with nested objects', () => {
const arr = [{ a: 1 }, { b: 2 }, { c: 3 }]; const arr = [{ a: 1 }, { b: 2 }, { c: 3 }];
const clonedArr = cloneDeep(arr); const clonedArr = cloneDeep(arr);
@ -319,4 +327,24 @@ describe('cloneDeep', () => {
expect(clonedError.cause).toBe(error.cause); expect(clonedError.cause).toBe(error.cause);
expect(clonedError.code).toBe(error.code); expect(clonedError.code).toBe(error.code);
}); });
it('should clone DataViews', () => {
const buffer = new Uint8Array([1, 2]).buffer;
const view = new DataView(buffer);
const cloned = cloneDeep(view);
expect(cloned).not.toBe(view);
expect(cloned.getInt8(0)).toBe(view.getInt8(0));
expect(cloned.getInt8(1)).toBe(view.getInt8(1));
})
it('should clone buffers', () => {
const buffer = Buffer.from([1, 2, 3]);
const cloned = cloneDeep(buffer);
expect(cloned).not.toBe(buffer);
expect(cloned).toEqual(buffer);
})
}); });

View File

@ -6,12 +6,14 @@ describe('isEqual', () => {
expect(isEqual(1, 1)).toBe(true); expect(isEqual(1, 1)).toBe(true);
expect(isEqual('hello', 'hello')).toBe(true); expect(isEqual('hello', 'hello')).toBe(true);
expect(isEqual(true, true)).toBe(true); expect(isEqual(true, true)).toBe(true);
expect(isEqual(100n, 100n)).toBe(true);
}); });
it('should return false for different primitive values', () => { it('should return false for different primitive values', () => {
expect(isEqual(1, 2)).toBe(false); expect(isEqual(1, 2)).toBe(false);
expect(isEqual('hello', 'world')).toBe(false); expect(isEqual('hello', 'world')).toBe(false);
expect(isEqual(true, false)).toBe(false); expect(isEqual(true, false)).toBe(false);
expect(isEqual(101n, 100n)).toBe(false);
}); });
it('should return true for NaN comparisons', () => { it('should return true for NaN comparisons', () => {
@ -50,6 +52,11 @@ describe('isEqual', () => {
const obj1 = { a: 1, b: { c: 2 } }; const obj1 = { a: 1, b: { c: 2 } };
const obj2 = { a: 1, b: { c: 2 } }; const obj2 = { a: 1, b: { c: 2 } };
expect(isEqual(obj1, obj2)).toBe(true); expect(isEqual(obj1, obj2)).toBe(true);
const obj3 = null;
const obj4 = null;
expect(isEqual(obj3, obj4)).toBe(true);
}); });
it('should return false for objects with different values', () => { it('should return false for objects with different values', () => {
@ -81,4 +88,23 @@ describe('isEqual', () => {
const arr2 = [1, 2]; const arr2 = [1, 2];
expect(isEqual(arr1, arr2)).toBe(false); expect(isEqual(arr1, arr2)).toBe(false);
}); });
it('should return true for equal array buffers', () => {
const buffer1 = new Uint8Array([1, 2, 3]).buffer;
const buffer2 = new Uint8Array([1, 2, 3]).buffer;
expect(isEqual(buffer1, buffer2)).toBe(true);
})
it('should return false for different array buffers', () => {
const buffer1 = new Uint8Array([1, 2, 3]).buffer;
const buffer2 = new Uint8Array([1, 2]).buffer;
expect(isEqual(buffer1, buffer2)).toBe(false);
const buffer3 = new Uint8Array([1, 2, 3]).buffer;
const buffer4 = new Uint8Array([1, 2, 4]).buffer;
expect(isEqual(buffer3, buffer4)).toBe(false);
})
}); });

View File

@ -68,7 +68,6 @@ function areObjectsEqual(a: any, b: any, stack?: Map<any, any>) {
} }
switch (aTag) { switch (aTag) {
case regexpTag:
case stringTag: case stringTag:
return a.toString() === b.toString(); return a.toString() === b.toString();
@ -196,8 +195,8 @@ function areObjectsEqual(a: any, b: any, stack?: Map<any, any>) {
} }
case objectTag: { case objectTag: {
if (a == null || b == null) { if (a === null || b === null) {
return a === b; return true;
} }
const areEqualInstances = const areEqualInstances =