Files
NapCatQQ/.pnpm-store/v3/files/a0/5d61d4c6c6337ea5c61a5954de5da917c3918de61b3ad6945bfe27319add4cd43ecdd647d672110fef3b9aa838bbd3751768b3a726bb604b67ee3ad2b447a4
T
TanTan e311ca3275
Build NapCat Artifacts / Type Check & Test (push) Waiting to run
docs: 仓库链接指向本镜像仓库
2026-11-13 09:25:58 +08:00

72 lines
2.1 KiB
Plaintext

import { noop } from '@internal/listenerMiddleware/utils'
import { AClockworkOrange } from './fixtures/book'
describe('Entity utils', () => {
describe(`selectIdValue()`, () => {
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(noop)
beforeEach(() => {
vi.resetModules() // this is important - it clears the cache
vi.stubEnv('NODE_ENV', 'development')
})
afterEach(() => {
vi.unstubAllEnvs()
vi.clearAllMocks()
})
afterAll(() => {
vi.restoreAllMocks()
})
it('should not warn when key does exist', async () => {
const { selectIdValue } = await import('../utils')
selectIdValue(AClockworkOrange, (book: any) => book.id)
expect(consoleWarnSpy).not.toHaveBeenCalled()
})
it('should warn when key does not exist in dev mode', async () => {
const { selectIdValue } = await import('../utils')
expect(process.env.NODE_ENV).toBe('development')
selectIdValue(AClockworkOrange, (book: any) => book.foo)
expect(consoleWarnSpy).toHaveBeenCalledOnce()
})
it('should warn when key is undefined in dev mode', async () => {
const { selectIdValue } = await import('../utils')
expect(process.env.NODE_ENV).toBe('development')
const undefinedAClockworkOrange = { ...AClockworkOrange, id: undefined }
selectIdValue(undefinedAClockworkOrange, (book: any) => book.id)
expect(consoleWarnSpy).toHaveBeenCalledOnce()
})
it('should not warn when key does not exist in prod mode', async () => {
vi.stubEnv('NODE_ENV', 'production')
const { selectIdValue } = await import('../utils')
selectIdValue(AClockworkOrange, (book: any) => book.foo)
expect(consoleWarnSpy).not.toHaveBeenCalled()
})
it('should not warn when key is undefined in prod mode', async () => {
vi.stubEnv('NODE_ENV', 'production')
const { selectIdValue } = await import('../utils')
const undefinedAClockworkOrange = { ...AClockworkOrange, id: undefined }
selectIdValue(undefinedAClockworkOrange, (book: any) => book.id)
expect(consoleWarnSpy).not.toHaveBeenCalled()
})
})
})