From d53b9b0200fb88148d36927239ce90d853fda68f Mon Sep 17 00:00:00 2001 From: chouchouji <1305974212@qq.com> Date: Mon, 28 Oct 2024 13:16:35 +0800 Subject: [PATCH] test: add general test cases --- tests/array.spec.ts | 2 +- tests/general.spec.ts | 48 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/tests/array.spec.ts b/tests/array.spec.ts index f96bc74..2bb78b5 100644 --- a/tests/array.spec.ts +++ b/tests/array.spec.ts @@ -12,7 +12,7 @@ import { shuffle, sum, sumBy, -} from '../src' +} from '../src/array' it('uniq', () => { const arr = uniq([1, 2, 2, 3, 4, 4]) diff --git a/tests/general.spec.ts b/tests/general.spec.ts index 1618159..3836b5d 100644 --- a/tests/general.spec.ts +++ b/tests/general.spec.ts @@ -1,7 +1,53 @@ import { it, expect } from 'vitest' -import { isNonEmptyArray } from '../src' +import { isNonEmptyArray, isString, isBoolean, isNumber, toTypeString } from '../src/general' it('isNonEmptyArray', () => { expect(isNonEmptyArray([])).toBe(false) + expect(isNonEmptyArray([1, 2])).toBe(true) }) + +it('toTypeString', () => { + expect(toTypeString([])).toBe('[object Array]') + expect(toTypeString({})).toBe('[object Object]') + expect(toTypeString(1)).toBe('[object Number]') + expect(toTypeString('')).toBe('[object String]') + expect(toTypeString(false)).toBe('[object Boolean]') + expect(toTypeString(null)).toBe('[object Null]') + expect(toTypeString(undefined)).toBe('[object Undefined]') +}) + +it('isString', () => { + expect(isString([])).toBe(false) + expect(isString(false)).toBe(false) + expect(isString(1)).toBe(false) + expect(isString(null)).toBe(false) + expect(isString(undefined)).toBe(false) + expect(isString({})).toBe(false) + + expect(isString('')).toBe(true) +}) + +it('isBoolean', () => { + expect(isBoolean([])).toBe(false) + expect(isBoolean(1)).toBe(false) + expect(isBoolean(null)).toBe(false) + expect(isBoolean(undefined)).toBe(false) + expect(isBoolean({})).toBe(false) + expect(isBoolean('')).toBe(false) + + expect(isBoolean(false)).toBe(true) + expect(isBoolean(true)).toBe(true) +}) + +it('isNumber', () => { + expect(isNumber([])).toBe(false) + expect(isNumber(false)).toBe(false) + expect(isNumber(null)).toBe(false) + expect(isNumber(undefined)).toBe(false) + expect(isNumber({})).toBe(false) + expect(isNumber('')).toBe(false) + + expect(isNumber(1)).toBe(true) + expect(isNumber(NaN)).toBe(true) +})