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

[@testing-library/jest-dom] Add new type for toHaveStyle matcher #42022

Merged
merged 2 commits into from Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion types/testing-library__jest-dom/index.d.ts
Expand Up @@ -28,7 +28,7 @@ declare namespace jest {
toHaveClass(...classNames: string[]): R;
toHaveFocus(): R;
toHaveFormValues(expectedValues: Record<string, unknown>): R;
toHaveStyle(css: string): R;
toHaveStyle(css: string | object): R;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this might be better expressed as string | Record<string, unknown> similar to the one above.

toHaveTextContent(text: string | RegExp, options?: { normalizeWhitespace: boolean }): R;
toHaveValue(value?: string | string[] | number): R;
toBeChecked(): R;
Expand Down
Expand Up @@ -22,6 +22,7 @@ expect(element).toHaveClass('cls1', 'cls2', 'cls3', 'cls4');
expect(element).toHaveFocus();
expect(element).toHaveFormValues({ foo: 'bar', baz: 1 });
expect(element).toHaveStyle('display: block');
expect(element).toHaveStyle({ display: 'block' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor thing, could you add another property that uses a different type, like width: 100 (just to verify that non-string values are also accepted)?

expect(element).toHaveTextContent('Text');
expect(element).toHaveTextContent(/Text/);
expect(element).toHaveTextContent('Text', { normalizeWhitespace: true });
Expand Down