You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-08-07 23:02:56 +03:00
Avoid an infinite loop in the interactive-auth test (#3722)
Reading the test "should fire stateUpdated callback with error when a request fails" it looks like this would always cause an infinite loop between doRequest and statusUpdated calls. I don't know why this wasn't a problem until we updated Jest to v29.5.4, but after that point it was. This change should fix the test failures for the Jest upgrade PR: https://github.com/matrix-org/matrix-js-sdk/pull/3670 .
This commit is contained in:
@@ -560,7 +560,7 @@ describe("InteractiveAuth", () => {
|
|||||||
expect(ia.getChosenFlow()?.stages).toEqual([AuthType.Password]);
|
expect(ia.getChosenFlow()?.stages).toEqual([AuthType.Password]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should fire stateUpdated callback if with error when encountered", async () => {
|
it("should fire stateUpdated callback with error when a request fails", async () => {
|
||||||
const doRequest = jest.fn();
|
const doRequest = jest.fn();
|
||||||
const stateUpdated = jest.fn();
|
const stateUpdated = jest.fn();
|
||||||
|
|
||||||
@@ -578,15 +578,20 @@ describe("InteractiveAuth", () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// first we expect a call here
|
// StateUpdated should be called. We call submitAuthDict() to trigger a request ...
|
||||||
|
let firstTime = true;
|
||||||
stateUpdated.mockImplementation((stage) => {
|
stateUpdated.mockImplementation((stage) => {
|
||||||
expect(stage).toEqual(AuthType.Password);
|
expect(stage).toEqual(AuthType.Password);
|
||||||
|
// Only trigger the request the first time, to avoid an infinite loop
|
||||||
|
if (firstTime) {
|
||||||
|
firstTime = false;
|
||||||
ia.submitAuthDict({
|
ia.submitAuthDict({
|
||||||
type: AuthType.Password,
|
type: AuthType.Password,
|
||||||
});
|
});
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// .. which should trigger a call here
|
// .. which which we then reject, so we can test the behaviour in that case.
|
||||||
doRequest.mockRejectedValue(new MatrixError({ errcode: "M_UNKNOWN", error: "This is an error" }));
|
doRequest.mockRejectedValue(new MatrixError({ errcode: "M_UNKNOWN", error: "This is an error" }));
|
||||||
|
|
||||||
await Promise.allSettled([ia.attemptAuth()]);
|
await Promise.allSettled([ia.attemptAuth()]);
|
||||||
|
Reference in New Issue
Block a user