-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f7dd95
commit 6bac34d
Showing
5 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
[test] | ||
coverage = true | ||
coverageThreshold = 1.0 | ||
coverageThreshold = 1.0 | ||
preload = "./happydom.ts" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { GlobalRegistrator } from "@happy-dom/global-registrator"; | ||
|
||
GlobalRegistrator.register(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,10 +48,11 @@ | |
}, | ||
"devDependencies": { | ||
"@biomejs/biome": "^1.4.1", | ||
"@happy-dom/global-registrator": "^12.10.3", | ||
"bun-types": "^1.0.17", | ||
"tsup": "^8.0.1", | ||
"type-fest": "^4.8.3", | ||
"typescript": "^5.3.3" | ||
}, | ||
"packageManager": "[email protected].14" | ||
"packageManager": "[email protected].17" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { beforeEach, describe, expect, it, jest } from "bun:test"; | ||
import { openPopup } from "./popup.js"; | ||
|
||
const window = globalThis.window as Window | undefined; | ||
if (!window) { | ||
throw new Error("window is not defined"); | ||
} | ||
|
||
describe("openPopup", () => { | ||
beforeEach(() => { | ||
jest.restoreAllMocks(); | ||
}); | ||
it("should return a new window object with the correct properties", () => { | ||
const url = "https://example.com"; | ||
const name = "popup"; | ||
const updatedWindow = { | ||
...window, | ||
location: { | ||
...window.location, | ||
href: url, | ||
}, | ||
name, | ||
}; | ||
window.open = jest.fn().mockReturnValue(updatedWindow); | ||
|
||
const windowFeatures = "width=500,height=500"; | ||
const newWindow = openPopup(url, name, windowFeatures); | ||
|
||
expect(window.open).toHaveBeenCalledWith( | ||
url, | ||
name, | ||
`noopener,noreferrer,${windowFeatures}`, | ||
); | ||
expect(newWindow).not.toBeNull(); | ||
expect(newWindow?.location.href).toBe(url); | ||
expect(newWindow?.name).toBe(name); | ||
expect(newWindow?.opener).toBeNull(); | ||
}); | ||
it("should not return a new window object if the browser fails to open the new browsing context", () => { | ||
window.open = jest.fn().mockReturnValue(null); | ||
|
||
const url = "https://example.com"; | ||
const name = "popup"; | ||
const windowFeatures = "width=500,height=500"; | ||
const newWindow = openPopup(url, name, windowFeatures); | ||
|
||
expect(window.open).toHaveBeenCalledWith( | ||
url, | ||
name, | ||
`noopener,noreferrer,${windowFeatures}`, | ||
); | ||
expect(newWindow).toBeNull(); | ||
}); | ||
}); |