Skip to content

Commit

Permalink
Merge pull request #6 from kcdraidgroup/aprillion
Browse files Browse the repository at this point in the history
fix #4 - expected console.error in tests
  • Loading branch information
JacobMGEvans committed Dec 15, 2020
2 parents 3fbdfc4 + 7340c5c commit f80a638
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/__tests__/labs/ViewLab.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import Lab from '../../shared/model/Lab'
import Patient from '../../shared/model/Patient'
import Permissions from '../../shared/model/Permissions'
import { RootState } from '../../shared/store'
import { expectOneConsoleError } from '../test-utils/console.utils'

const mockStore = createMockStore<RootState, any>([thunk])

Expand Down Expand Up @@ -196,6 +197,7 @@ describe('View Lab', () => {
const { wrapper } = await setup(expectedLab, [Permissions.ViewLab, Permissions.CompleteLab])

const expectedError = { message: 'some message', result: 'some result feedback' } as LabError
expectOneConsoleError(expectedError)
jest.spyOn(validateUtil, 'validateLabComplete').mockReturnValue(expectedError)

const completeButton = wrapper.find(Button).at(1)
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/labs/hooks/useCompleteLab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { LabError } from '../../../labs/utils/validate-lab'
import * as validateLabUtils from '../../../labs/utils/validate-lab'
import LabRepository from '../../../shared/db/LabRepository'
import Lab from '../../../shared/model/Lab'
import { expectOneConsoleError } from '../../test-utils/console.utils'
import executeMutation from '../../test-utils/use-mutation.util'

describe('Use Complete lab', () => {
Expand Down Expand Up @@ -44,6 +45,7 @@ describe('Use Complete lab', () => {
result: 'some result error message',
} as LabError

expectOneConsoleError(expectedLabError)
jest.spyOn(validateLabUtils, 'validateLabComplete').mockReturnValue(expectedLabError)

await act(async () => {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/labs/hooks/useRequestLab.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as validateLabRequest from '../../../labs/utils/validate-lab'
import { LabError } from '../../../labs/utils/validate-lab'
import LabRepository from '../../../shared/db/LabRepository'
import Lab from '../../../shared/model/Lab'
import { expectOneConsoleError } from '../../test-utils/console.utils'
import executeMutation from '../../test-utils/use-mutation.util'

describe('Use Request lab', () => {
Expand Down Expand Up @@ -45,6 +46,7 @@ describe('Use Request lab', () => {
type: 'error type',
} as LabError

expectOneConsoleError(expectedError)
jest.spyOn(validateLabRequest, 'validateLabRequest').mockReturnValue(expectedError)

await act(async () => {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/labs/requests/NewLabRequest.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PatientRepository from '../../../shared/db/PatientRepository'
import Lab from '../../../shared/model/Lab'
import Patient from '../../../shared/model/Patient'
import { RootState } from '../../../shared/store'
import { expectOneConsoleError } from '../../test-utils/console.utils'

const mockStore = createMockStore<RootState, any>([thunk])
describe('New Lab Request', () => {
Expand Down Expand Up @@ -112,6 +113,7 @@ describe('New Lab Request', () => {
type: 'some type error',
} as LabError

expectOneConsoleError(error)
jest.spyOn(validationUtil, 'validateLabRequest').mockReturnValue(error)

it('should display errors', async () => {
Expand Down
6 changes: 4 additions & 2 deletions src/__tests__/patients/hooks/useAddCareGoal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PatientRepository from '../../../shared/db/PatientRepository'
import CareGoal, { CareGoalStatus, CareGoalAchievementStatus } from '../../../shared/model/CareGoal'
import Patient from '../../../shared/model/Patient'
import * as uuid from '../../../shared/util/uuid'
import { expectOneConsoleError } from '../../test-utils/console.utils'
import executeMutation from '../../test-utils/use-mutation.util'

describe('use add care goal', () => {
Expand Down Expand Up @@ -59,8 +60,9 @@ describe('use add care goal', () => {
const expectedError = {
message: 'patient.careGoal.error.unableToAdd',
description: 'some error',
}
jest.spyOn(validateCareGoal, 'default').mockReturnValue(expectedError as CareGoalError)
} as CareGoalError
expectOneConsoleError(expectedError)
jest.spyOn(validateCareGoal, 'default').mockReturnValue(expectedError)
jest.spyOn(PatientRepository, 'saveOrUpdate')

try {
Expand Down
9 changes: 7 additions & 2 deletions src/__tests__/patients/hooks/useAddCarePlan.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import PatientRepository from '../../../shared/db/PatientRepository'
import CarePlan, { CarePlanIntent, CarePlanStatus } from '../../../shared/model/CarePlan'
import Patient from '../../../shared/model/Patient'
import * as uuid from '../../../shared/util/uuid'
import { expectOneConsoleError } from '../../test-utils/console.utils'
import executeMutation from '../../test-utils/use-mutation.util'

describe('use add care plan', () => {
Expand Down Expand Up @@ -45,8 +46,12 @@ describe('use add care plan', () => {
})

it('should throw an error if validation fails', async () => {
const expectedError = { message: 'patient.carePlan.error.unableToAdd', title: 'some error' }
jest.spyOn(validateCarePlan, 'default').mockReturnValue(expectedError as CarePlanError)
const expectedError = {
message: 'patient.carePlan.error.unableToAdd',
title: 'some error',
} as CarePlanError
expectOneConsoleError(expectedError)
jest.spyOn(validateCarePlan, 'default').mockReturnValue(expectedError)
jest.spyOn(PatientRepository, 'saveOrUpdate')

try {
Expand Down
2 changes: 2 additions & 0 deletions src/__tests__/patients/hooks/useAddPatientDiagnosis.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PatientRepository from '../../../shared/db/PatientRepository'
import Diagnosis, { DiagnosisStatus } from '../../../shared/model/Diagnosis'
import Patient from '../../../shared/model/Patient'
import * as uuid from '../../../shared/util/uuid'
import { expectOneConsoleError } from '../../test-utils/console.utils'
import executeMutation from '../../test-utils/use-mutation.util'

describe('use add diagnosis', () => {
Expand All @@ -16,6 +17,7 @@ describe('use add diagnosis', () => {

it('should throw an error if diagnosis validation fails', async () => {
const expectedError = { name: 'some error' }
expectOneConsoleError(expectedError as Error)
jest.spyOn(validateDiagnosis, 'default').mockReturnValue(expectedError)
jest.spyOn(PatientRepository, 'saveOrUpdate')

Expand Down
5 changes: 5 additions & 0 deletions src/__tests__/test-utils/console.utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export function expectOneConsoleError(expected: Error) {
jest.spyOn(console, 'error').mockImplementationOnce((actual) => {
expect(actual).toEqual(expected)
})
}

0 comments on commit f80a638

Please sign in to comment.