vitest-dev / eslint-plugin-vitest

eslint plugin for vitest
MIT License
325 stars 44 forks source link

fix(valid-expect): allow `expect(value, "message")` #518

Closed azu closed 2 months ago

azu commented 2 months ago

Allow to use expect(value, "message").toBe(1) pattern.

📝 Note: TypeScript type information is required for accurate implementation. Since ASTs may not contain type, only simple string literals and template literals are supported.

OK:

expect(value, "string literal").toBe(1);
expect(value, `template literal`).toBe(1);

const message = "message";
expect(value, `${message}`).toBe(1);

NG:

// variable is not allowed - it is limitation of current implemtation
const message = "message";
expect(value, message).toBe(1);
// non string types
expect(value, {}).toBe(1);
expect(value, []).toBe(1);
expect(value, 1).toBe(1);

Note

This feature is undocument yet, but vitest type definition define it.

Waiting until it is documented may be the right thing to do.

fix https://github.com/vitest-dev/eslint-plugin-vitest/issues/503