Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加单元测试 getValueType.test.js #118

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions lib/internal/getValueType.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { it, expect, describe } from 'vitest';
import yd_internal_getValueType from './getValueType.js';

describe('yd_internal_getValueType', () => {
it("should return '[object Null]' for null", () => {
expect(yd_internal_getValueType(null)).toBe('[object Null]');
});

it("should return '[object Undefined]' for undefined", () => {
expect(yd_internal_getValueType(undefined)).toBe('[object Undefined]');
});

it("should return '[object String]' for strings", () => {
expect(yd_internal_getValueType('')).toBe('[object String]');
expect(yd_internal_getValueType('hello world')).toBe('[object String]');
});

it("should return '[object Number]' for numbers", () => {
expect(yd_internal_getValueType(100)).toBe('[object Number]');
expect(yd_internal_getValueType(NaN)).toBe('[object Number]');
});

it("should return '[object Boolean]' for booleans", () => {
expect(yd_internal_getValueType(true)).toBe('[object Boolean]');
expect(yd_internal_getValueType(false)).toBe('[object Boolean]');
});

it("should return '[object Array]' for arrays", () => {
expect(yd_internal_getValueType([])).toBe('[object Array]');
expect(yd_internal_getValueType([1, 2, 3])).toBe('[object Array]');
});

it("should return '[object Object]' for objects", () => {
expect(yd_internal_getValueType({})).toBe('[object Object]');
expect(yd_internal_getValueType({ key: 'value' })).toBe('[object Object]');
});

it("should return '[object Function]' for functions", () => {
expect(yd_internal_getValueType(() => {})).toBe('[object Function]');
expect(yd_internal_getValueType(function () {})).toBe('[object Function]');
});

it("should return '[object Date]' for Date objects", () => {
expect(yd_internal_getValueType(new Date())).toBe('[object Date]');
expect(yd_internal_getValueType('2024-01-01')).not.toBe('[object Date]');
});

it("should return '[object Promise]' for promises", () => {
expect(yd_internal_getValueType(Promise.resolve())).toBe('[object Promise]');
expect(yd_internal_getValueType(() => Promise.resolve())).not.toBe('[object Promise]');
expect(yd_internal_getValueType(() => Promise.resolve())).toBe('[object Function]');
});
});