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

Avoid making assertions about unrelated warning calls #4933

Closed
wants to merge 2 commits into from
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
Original file line number Diff line number Diff line change
Expand Up @@ -1065,9 +1065,8 @@ describe('usePreloadedQuery', () => {

describe('when loadQuery is passed a preloadedQuery that was disposed', () => {
it('warns that the preloadedQuery has already been disposed', () => {
const expectWarningMessage = expect.stringMatching(
/^usePreloadedQuery\(\): Expected preloadedQuery to not be disposed/,
);
const expectWarningMessage =
/^usePreloadedQuery\(\): Expected preloadedQuery to not be disposed/;
const prefetched = loadQuery(environment, preloadableConcreteRequest, {
id: '1',
});
Expand All @@ -1091,19 +1090,23 @@ describe('usePreloadedQuery', () => {
};

render();
expect(warning).toBeCalledTimes(1);
expect(warning).toHaveBeenLastCalledWith(
true, // invariant holds
expectWarningMessage,
// $FlowFixMe[prop-missing]
const warningCallsBefore = warning.mock.calls.filter(([_, message]) =>
message.match(expectWarningMessage),
);
expect(warningCallsBefore.length).toBe(1);
// invariant holds
expect(warningCallsBefore[0][0]).toBe(true);

prefetched.dispose();
render();
expect(warning).toBeCalledTimes(2);
expect(warning).toHaveBeenLastCalledWith(
false, // invariant broken
expectWarningMessage,
// $FlowFixMe[prop-missing]
const warningCallsAfter = warning.mock.calls.filter(([_, message]) =>
message.match(expectWarningMessage),
);
expect(warningCallsAfter.length).toBe(2);
// invariant broken
expect(warningCallsAfter[1][0]).toBe(false);
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -646,10 +646,11 @@ describe.each([['New', useRefetchableFragmentInternal]])(
refetch({id: '4'});
});

expect(warning).toHaveBeenCalledTimes(1);
// $FlowFixMe[prop-missing]
const triggeredWarnings = warning.mock.calls.filter(args => !args[0]);
expect(triggeredWarnings.length).toBe(1);
expect(
// $FlowFixMe[prop-missing]
warning.mock.calls[0][1].includes(
triggeredWarnings[0][1].includes(
'Relay: Unexpected call to `refetch` while using a null fragment ref',
),
).toEqual(true);
Expand Down
Loading