Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions types/testing-library__jest-dom/matchers.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
/// <reference types="jest" />

declare namespace matchers {
interface TestingLibraryMatchers<E, R> extends Record<string, any> {
interface TestingLibraryMatchers<E, R> {
/**
* @deprecated
* since v1.9.0
Expand Down Expand Up @@ -657,7 +659,11 @@ declare namespace matchers {
*/
toHaveErrorMessage(text?: string | RegExp | E): R;
}

// Needs to extend Record<string, any> to be accepted by expect.extend()
// as it requires a string index signature.
interface TestingLibraryMatchersExport extends Record<string, jest.CustomMatcher>, TestingLibraryMatchers<any, jest.CustomMatcherResult> {}
}

declare const matchers: matchers.TestingLibraryMatchers<any, void>;
declare const matchers: matchers.TestingLibraryMatchersExport;
export = matchers;
Original file line number Diff line number Diff line change
Expand Up @@ -70,54 +70,5 @@ customExpect(element).toHaveErrorMessage('Invalid time: the time must be between
customExpect(element).toHaveErrorMessage(/invalid time/i);
customExpect(element).toHaveErrorMessage(expect.stringContaining('Invalid time'));

customExpect(element).not.toBeInTheDOM();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@kryops How come you removed all the .not test cases?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The testing library types actually do not contain not, only the Jest types do.

These tests were only green because the types mapped every unkown property to any before, but I don't think they really made sense.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah I see, because of the customExpect. Looks like the jest suite is still testing .not so this looks good :)

customExpect(element).not.toBeInTheDOM(document.body);
customExpect(element).not.toBeInTheDocument();
customExpect(element).not.toBeVisible();
customExpect(element).not.toBeEmpty();
customExpect(element).not.toBeEmptyDOMElement();
customExpect(element).not.toBeDisabled();
customExpect(element).not.toBeEnabled();
customExpect(element).not.toBeInvalid();
customExpect(element).not.toBeRequired();
customExpect(element).not.toBeValid();
customExpect(element).not.toContainElement(document.body);
customExpect(element).not.toContainElement(null);
customExpect(element).not.toContainHTML('body');
customExpect(element).not.toHaveAttribute('attr');
customExpect(element).not.toHaveAttribute('attr', true);
customExpect(element).not.toHaveAttribute('attr', 'yes');
customExpect(element).not.toHaveClass();
customExpect(element).not.toHaveClass('cls1');
customExpect(element).not.toHaveClass('cls1', 'cls2', 'cls3', 'cls4');
customExpect(element).not.toHaveClass('cls1', { exact: true });
customExpect(element).not.toHaveDisplayValue('str');
customExpect(element).not.toHaveDisplayValue(['str1', 'str2']);
customExpect(element).not.toHaveDisplayValue(/str/);
customExpect(element).not.toHaveDisplayValue([/str1/, 'str2']);
customExpect(element).not.toHaveFocus();
customExpect(element).not.toHaveFormValues({ foo: 'bar', baz: 1 });
customExpect(element).not.toHaveStyle('display: block');
customExpect(element).not.toHaveTextContent('Text');
customExpect(element).not.toHaveTextContent(/Text/);
customExpect(element).not.toHaveTextContent('Text', { normalizeWhitespace: true });
customExpect(element).not.toHaveTextContent(/Text/, { normalizeWhitespace: true });
customExpect(element).not.toHaveValue();
customExpect(element).not.toHaveValue('str');
customExpect(element).not.toHaveValue(['str1', 'str2']);
customExpect(element).not.toHaveValue(1);
customExpect(element).not.toBeChecked();
customExpect(element).not.toHaveDescription('some description');
customExpect(element).not.toHaveDescription();
customExpect(element).not.toHaveAccessibleDescription('some description');
customExpect(element).not.toHaveAccessibleDescription();

customExpect(element).not.toHaveAccessibleErrorMessage();
customExpect(element).not.toHaveAccessibleErrorMessage('There is no date');
customExpect(element).not.toHaveAccessibleErrorMessage(/everything is valid/i);

customExpect(element).not.toHaveAccessibleName('a label');
customExpect(element).not.toHaveAccessibleName();
customExpect(element).not.toBePartiallyChecked();
customExpect(element).not.toHaveErrorMessage();
customExpect(element).not.toHaveErrorMessage('Pikachu!');
// @ts-expect-error
customExpect(element).nonExistentProperty();
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,6 @@ expect(element).not.toHaveAccessibleName();
expect(element).not.toBePartiallyChecked();
expect(element).not.toHaveErrorMessage();
expect(element).not.toHaveErrorMessage('Pikachu!');

// @ts-expect-error
expect(element).nonExistentProperty();