Skip to content

Commit 5d23509

Browse files
Copilotthet
andauthored
fix: restore Pattern.prototype.base_url via afterEach in navigation tests
Agent-Logs-Url: https://github.com/Patternslib/Patterns/sessions/49709a1a-a4ed-4d5c-aac9-6c685d170fd5 Co-authored-by: thet <170891+thet@users.noreply.github.com>
1 parent 92056b3 commit 5d23509

1 file changed

Lines changed: 6 additions & 9 deletions

File tree

src/pat/navigation/navigation.test.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -227,15 +227,21 @@ describe("2 - Navigation pattern tests - mark after navigation injection", funct
227227

228228
describe("3 - Navigation pattern tests - Mark items based on URL", () => {
229229
let _window_location;
230+
let _originalBaseUrl;
230231

231232
beforeEach(() => {
232233
_window_location = global.window.location;
233234
delete global.window.location;
234235
document.body.innerHTML = "";
236+
_originalBaseUrl = Pattern.prototype.base_url;
237+
Pattern.prototype.base_url = function () {
238+
return "https://patternslib.com/";
239+
};
235240
});
236241

237242
afterEach(() => {
238243
global.window.location = _window_location;
244+
Pattern.prototype.base_url = _originalBaseUrl;
239245
});
240246

241247
it("navigation roundtrip", async () => {
@@ -281,12 +287,6 @@ describe("3 - Navigation pattern tests - Mark items based on URL", () => {
281287
</nav>
282288
`;
283289

284-
// Mock the base_url method at the prototype level to avoid JSDOM navigation issues
285-
const originalBaseUrl = Pattern.prototype.base_url;
286-
Pattern.prototype.base_url = function () {
287-
return "https://patternslib.com/";
288-
};
289-
290290
// Set portal URL directly on document body
291291
document.body.dataset.portalUrl = "https://patternslib.com";
292292

@@ -372,9 +372,6 @@ describe("3 - Navigation pattern tests - Mark items based on URL", () => {
372372
expect(document.querySelectorAll(".current").length).toBe(2);
373373
expect(document.querySelectorAll(".inPath").length).toBe(0);
374374
expect(document.querySelector(".current a")).toBe(it4);
375-
376-
// Restore the original method
377-
Pattern.prototype.base_url = originalBaseUrl;
378375
});
379376
});
380377

0 commit comments

Comments
 (0)