Skip to content

Conversation

@porada
Copy link

@porada porada commented Nov 26, 2025

What

The following matchers currently force casts on their arguments, even though they shouldn’t:

expect(link).toHaveAttribute({
    rel: expect.stringContaining('opener') as unknown
});

expect(form).toHaveFormValues({
    foo: 'bar',
    baz: expect.any(Number) as unknown
});

expect(element).toHaveStyle({
    display: expect.any(String) as unknown
    width: 1024,
});

Why

Casts add noise to otherwise valid expectations. Asymmetric matchers are a native feature in all supported test frameworks, so they shouldn’t require workarounds.

How

This PR widens the argument types from unknown to any, allowing asymmetric matcher values to be passed directly:

expect(link).toHaveAttribute({
    rel: expect.stringContaining('opener') // ✅
});

expect(form).toHaveFormValues({
    baz: expect.any(Number) // ✅
});

expect(element).toHaveStyle({
    display: expect.any(String) // ✅
});

Checklist

  • Documentation
  • Tests
  • Updated type definitions
  • Ready to be merged

@porada
Copy link
Author

porada commented Nov 26, 2025

I didn’t tick Documentation as this PR doesn’t affect docs.

@porada porada marked this pull request as ready for review November 26, 2025 16:13
@porada porada changed the title Add support asymmetric matcher types for toHaveAttribute/toHaveFormValues/toHaveStyle Add support for asymmetric matcher types Nov 26, 2025
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.

1 participant