/* oxlint-disable typescript/ban-ts-comment */ import { describe, expectTypeOf, test, vi } from 'vitest' describe('test', () => { test('some-test', () => { expectTypeOf(Date).toBeConstructibleWith(new Date()) expectTypeOf(Date).toBeConstructibleWith('01-01-2000') type ResponsiveProp = T | T[] | { xs?: T; sm?: T; md?: T } const getResponsiveProp = (_props: T): ResponsiveProp => ({}) interface CSSProperties { margin?: string padding?: string } const cssProperties: CSSProperties = { margin: '1px', padding: '2px' } expectTypeOf(getResponsiveProp(cssProperties)) .exclude() // .exclude<{ xs?: unknown }>() .toEqualTypeOf() }) describe('test2', () => { test('some-test 2', () => { expectTypeOf(Promise.resolve('string')).resolves.toEqualTypeOf() expectTypeOf(45).toEqualTypeOf(45) }) }) test('ignored error', () => { // @ts-ignore 45 is not a string expectTypeOf(45).toEqualTypeOf() }) test('expected error', () => { // @ts-expect-error 45 is not a string expectTypeOf(45).toEqualTypeOf() }) test('spyOn googleapis compiles', () => { // googleapis-like typing to reproduce https://github.com/vitest-dev/vitest/issues/3141 // oxlint-disable-next-line no-unassigned-vars let google!: { [key: string]: unknown sheets: () => { foo: string } } vi.spyOn(google, 'sheets').mockReturnValue({ foo: 'bar' }) // @ts-expect-error vi.spyOn(google, 'sheets').mockReturnValue({ foo: 1234 }) }) test('spyOn private and protected methods compiles', () => { class TestClass { private privateMethod(): number { return 42 } protected protectedMethod(): string { return '42' } } const instance = new TestClass() vi.spyOn(instance, 'privateMethod').mockReturnValue(1) vi.spyOn(instance, 'protectedMethod').mockReturnValue('1') // @ts-expect-error private method returns number vi.spyOn(instance, 'privateMethod').mockReturnValue('1') // @ts-expect-error protected method returns string vi.spyOn(instance, 'protectedMethod').mockReturnValue(1) // @ts-expect-error unknown methods are rejected vi.spyOn(instance, 'unknownMethod') }) }) expectTypeOf({ wolk: 'true' }).toHaveProperty('wolk')