Skip to content

Commit

Permalink
test: add general test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Oct 28, 2024
1 parent c90908a commit d53b9b0
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/array.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
shuffle,
sum,
sumBy,
} from '../src'
} from '../src/array'

it('uniq', () => {
const arr = uniq([1, 2, 2, 3, 4, 4])
Expand Down
48 changes: 47 additions & 1 deletion tests/general.spec.ts
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit d53b9b0

Please sign in to comment.