Skip to content

Commit

Permalink
Merge pull request #89 from nearform/fix/jest_bump
Browse files Browse the repository at this point in the history
fix: jest mock restore changes
  • Loading branch information
Ademsk1 authored Oct 17, 2023
2 parents b289b61 + 4d3a305 commit 0ad5db0
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tests/Authentication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ const TEST_SERVICE_ACCOUNT = {}
const TEST_VERSION = 'ver'
const mockedStatusCode = jest.fn()

const mockedEvalute = jest.fn()
const mockedEvaluate = jest.fn()
const mockedAddScriptTag = jest.fn()
const pageMock: Page = {
evaluate: mockedEvalute,
evaluate: mockedEvaluate,
addScriptTag: mockedAddScriptTag
} as unknown as Page

Expand All @@ -39,13 +39,12 @@ const mockedResponse = () =>

describe('Authentication Class tests', () => {
beforeEach(() => {
// mockedEvalute.mockReset()
jest.spyOn(authSetup, 'getToken').mockReturnValue(Promise.resolve('hello'))
jest.spyOn(global, 'fetch').mockImplementation(mockedResponse)
mockedStatusCode.mockReturnValue(200)
})
afterEach(() => {
jest.restoreAllMocks()
jest.clearAllMocks()
})
test('Authentication class initialised w/ log in/out functions', () => {
const Auth = generateAuth()
Expand All @@ -56,7 +55,7 @@ describe('Authentication Class tests', () => {
test('Logging in calls the evaluate function of the page + addScriptTag', async () => {
const Auth = generateAuth()
await Auth.login(pageMock)
expect(mockedEvalute).toHaveBeenCalled()
expect(mockedEvaluate).toHaveBeenCalled()
expect(mockedAddScriptTag).toHaveBeenCalledTimes(3)
})
test('Bad version number throws', async () => {
Expand All @@ -70,7 +69,7 @@ describe('Authentication Class tests', () => {
const Auth = generateAuth()
Auth.userSet = true
await Auth.login(pageMock)
expect(mockedEvalute).not.toHaveBeenCalled()
expect(mockedEvaluate).not.toHaveBeenCalled()
})
test('Logging out resets user', async () => {
const Auth = generateAuth()
Expand Down

0 comments on commit 0ad5db0

Please sign in to comment.