diff --git a/src/Poll.test.tsx b/src/Poll.test.tsx index 245e6c48..ddd6ac49 100644 --- a/src/Poll.test.tsx +++ b/src/Poll.test.tsx @@ -194,6 +194,58 @@ describe("Poll", () => { await wait(() => expect(children.mock.calls.length).toBe(3)); expect(children.mock.calls[2][0]).toEqual({ data: "hello you" }); }); + + it("should stop polling if no polling index returned", async () => { + // render 1: loading + nock("https://my-awesome-api.fake", { + reqheaders: { + prefer: "wait=1s;", + }, + }) + .get("/") + .reply(200, { data: "hello" }, { "x-polling-index": "1" }); + // render 2: data (hello) + + const lastResponseWithoutIndex = { data: "new data" }; + + // render 3 data (new data) + nock("https://my-awesome-api.fake", { + reqheaders: { + prefer: "wait=1s;index=1", + }, + }) + .get("/") + .reply(200, lastResponseWithoutIndex); + + // render 4 (shouldn't happen) + nock("https://my-awesome-api.fake", { + reqheaders: { + prefer: "wait=1s;", + }, + }) + .get("/") + .reply( + 200, + { data: "You shouldn't get here because the previous one had no polling index." }, + { "x-polling-index": "3" }, + ); + + const children = jest.fn(); + children.mockReturnValue(
); + + render( +