Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
tests(core/seo): fix racy tests (speced#3999)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoscaceres authored Feb 1, 2022
1 parent 966ceab commit fcda45d
Showing 1 changed file with 6 additions and 29 deletions.
35 changes: 6 additions & 29 deletions tests/spec/core/seo-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,8 @@ describe("Core — Seo", () => {
body: makeDefaultBody(),
};
const doc = await makeRSDoc(ops);
await doc.respec.ready;
await new Promise(resolve => {
const check = () => {
const hasMetaDesc = doc.querySelectorAll("meta[name=description]");
expect(hasMetaDesc).toHaveSize(0);
resolve();
};
window.requestIdleCallback ? window.requestIdleCallback(check) : check();
});
const hasMetaDesc = doc.querySelectorAll("meta[name=description]");
expect(hasMetaDesc).toHaveSize(0);
});

it("inserts a meta element for the description after processing", async () => {
Expand All @@ -37,25 +30,9 @@ describe("Core — Seo", () => {
body: makeDefaultBody(),
};
const doc = await makeRSDoc(ops);
await doc.respec.ready;
await new Promise(resolve => {
const check = () => {
const hasMetaDesc = doc.querySelectorAll(
"meta[name=description]"
).length;
// Firefox is buggy, short circuit
if (navigator.userAgent.includes("Firefox") && !hasMetaDesc) {
expect(true).toBe(true);
return;
}
expect(hasMetaDesc).toBe(1);
const meta = doc.head.querySelector("meta[name=description]");
expect(meta.content).toBe("Pass");
resolve();
};
window.requestIdleCallback
? doc.defaultView.requestIdleCallback(check)
: check();
});
const hasMetaDesc = doc.querySelectorAll("meta[name=description]").length;
expect(hasMetaDesc).toBe(1);
const meta = doc.head.querySelector("meta[name=description]");
expect(meta.content).toBe("Pass");
});
});

0 comments on commit fcda45d

Please sign in to comment.