Skip to content

Commit d29391a

Browse files
authored
Merge pull request #3714 from cdr/jsjoeio-add-login-test
feat(test): check login.ts when base missing
2 parents b365830 + 7ad536b commit d29391a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

test/browser/pages/login.test.ts

+45
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,49 @@ describe("login", () => {
4242
expect(el?.value).toBe("/hello-world")
4343
})
4444
})
45+
describe("there is not an element with id 'base'", () => {
46+
let spy: jest.SpyInstance
47+
48+
beforeAll(() => {
49+
// This is important because we're manually requiring the file
50+
// If you don't call this before all tests
51+
// the module registry from other tests may cause side effects.
52+
jest.resetModuleRegistry()
53+
})
54+
55+
beforeEach(() => {
56+
const dom = new JSDOM()
57+
global.document = dom.window.document
58+
spy = jest.spyOn(document, "getElementById")
59+
60+
const location: LocationLike = {
61+
pathname: "/healthz",
62+
origin: "http://localhost:8080",
63+
}
64+
65+
global.location = location as Location
66+
})
67+
68+
afterEach(() => {
69+
spy.mockClear()
70+
jest.resetModules()
71+
// Reset the global.document
72+
global.document = undefined as any as Document
73+
global.location = undefined as any as Location
74+
})
75+
76+
afterAll(() => {
77+
jest.restoreAllMocks()
78+
})
79+
80+
it("should do nothing", () => {
81+
spy.mockImplementation(() => null)
82+
// Load file
83+
require("../../../src/browser/pages/login")
84+
85+
// It's called once by getOptions in the top of the file
86+
// and then another to get the base element
87+
expect(spy).toHaveBeenCalledTimes(2)
88+
})
89+
})
4590
})

0 commit comments

Comments
 (0)