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

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

Merged
merged 3 commits into from
Aug 26, 2024

Conversation

azu
Copy link
Contributor

@azu azu commented Aug 26, 2024

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 #503

Copy link
Member

@veritem veritem left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@veritem veritem merged commit c0d05fd into vitest-dev:main Aug 26, 2024
@azu azu deleted the fix/6337 branch August 26, 2024 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

valid-expect doesn't recognize the second parameter of expect
2 participants