vitest/prefer-expect-type-of
@vitest/eslint-plugin
Safe autofix
eslint.config.js
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-expect-type-of": "error",
},
},
];Enforce using expect(...).toBeTypeOf(...) instead of expect(typeof ...).toBe(...)
import { test, expect } from 'vitest'
test('type checking', () => {
expect(typeof 'hello').toBe('string')
expect(typeof 42).toBe('number')
expect(typeof true).toBe('boolean')
expect(typeof {}).toBe('object')
expect(typeof (() => {})).toBe('function')
expect(typeof Symbol()).toBe('symbol')
expect(typeof 123n).toBe('bigint')
expect(typeof undefined).toBe('undefined')
})import { test, expect } from 'vitest'
test('type checking', () => {
expect('hello').toBeTypeOf('string')
expect(42).toBeTypeOf('number')
expect(true).toBeTypeOf('boolean')
expect({}).toBeTypeOf('object')
expect(() => {}).toBeTypeOf('function')
expect(Symbol()).toBeTypeOf('symbol')
expect(123n).toBeTypeOf('bigint')
expect(undefined).toBeTypeOf('undefined')
})Examples from the ESLint documentation.
No tracked preset enables this rule, so it has no reach yet.
None of the tracked presets enable this rule. Turn it on with the config below.
vitest/prefer-expect-type-of
@vitest/eslint-plugin
import vitest from "@vitest/eslint-plugin";
export default [
{
plugins: { vitest },
rules: {
"vitest/prefer-expect-type-of": "error",
},
},
];vitest/prefer-expect-type-of
vitest plugin · style
{
"plugins": [
"vitest"
],
"rules": {
"vitest/prefer-expect-type-of": "error"
}
}Biome does not have this rule.
Enforce using expect().resolves over expect(await ...) syntax
Enforce using expect assertions instead of callbacks
Enforce mock resolved/rejected shorthands for promises