Skip to content

feat(test): check login.ts when base missing #3714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 45 additions & 0 deletions test/browser/pages/login.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,49 @@ describe("login", () => {
expect(el?.value).toBe("/hello-world")
})
})
describe("there is not an element with id 'base'", () => {
let spy: jest.SpyInstance

beforeAll(() => {
// This is important because we're manually requiring the file
// If you don't call this before all tests
// the module registry from other tests may cause side effects.
jest.resetModuleRegistry()
})

beforeEach(() => {
const dom = new JSDOM()
global.document = dom.window.document
spy = jest.spyOn(document, "getElementById")

const location: LocationLike = {
pathname: "/healthz",
origin: "http://localhost:8080",
}

global.location = location as Location
})

afterEach(() => {
spy.mockClear()
jest.resetModules()
// Reset the global.document
global.document = undefined as any as Document
global.location = undefined as any as Location
})

afterAll(() => {
jest.restoreAllMocks()
})

it("should do nothing", () => {
spy.mockImplementation(() => null)
// Load file
require("../../../src/browser/pages/login")

// It's called once by getOptions in the top of the file
// and then another to get the base element
expect(spy).toHaveBeenCalledTimes(2)
})
})
})