Skip to content

Commit

Permalink
jest clean up and terminal clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
cameron-eyds committed Nov 24, 2023
1 parent 8a6942d commit a499018
Show file tree
Hide file tree
Showing 13 changed files with 14 additions and 77 deletions.
2 changes: 1 addition & 1 deletion ppr-ui/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare namespace jest {
declare namespace vitest {
interface Matchers<R> {
toHaveNoViolations(): R;
}
Expand Down
14 changes: 0 additions & 14 deletions ppr-ui/jest.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion ppr-ui/src/components/parties/Parties.vue
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ import {
computed
} from 'vue'
import { useStore } from '@/store/store'
import PartySummary from './PartySummary.vue' // need to import like this for jest tests - cyclic issue?
import PartySummary from './PartySummary.vue' // need to import like this for vitests - cyclic issue?
import { Debtors } from '@/components/parties/debtor'
import {
RegisteringPartyChange,
Expand Down
10 changes: 5 additions & 5 deletions ppr-ui/src/utils/feature-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ export const defaultFlagSet: LDFlagSet = {
'search-registration-number': true,
'search-serial-number': true,
'mhr-ui-enabled': true, // Mhr Search - default true: Should remove from codebase
'mhr-registration-enabled': true, // Enables MHR table tab
'mhr-transfer-enabled': true, // Enables changes to base MHR Home Owners within the MHR Information flow
'mhr-registration-enabled': false, // Enables MHR table tab
'mhr-transfer-enabled': false, // Enables changes to base MHR Home Owners within the MHR Information flow
'assets-tiptap-enabled': true, // Enables new TipTap wysiwyg editor - default true: Should remove from codebase
'mhr-exemption-enabled': true,
'mhr-exemption-enabled': false,
'mhr-transport-permit-enabled': '',
'mhr-user-access-enabled': true,
'sentry-enable': true, // by default, no sentry logs
'mhr-user-access-enabled': false,
'sentry-enable': false, // by default, no sentry logs
'banner-text': '' // by default, there is no banner text
}
/**
Expand Down
2 changes: 1 addition & 1 deletion ppr-ui/src/utils/validation-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const numbersOnly = /^\d+$/
const lettersOnly = /^[A-z]+$/
const regNumber = /^\d{6}[A-z]{1}$/
const regNumberPartial = /^\d{1,6}[A-z]{0,1}$/
// replaceAll fails in jest so use regex
// replaceAll fails in vitest so use regex
const dash = /-/g

export function validateSearchAction (
Expand Down
1 change: 0 additions & 1 deletion ppr-ui/tests/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import vuetify from '@/plugins/vuetify'
import * as matchers from 'vitest-axe/matchers'
import 'vitest-axe/extend-expect'
import { expect } from 'vitest'
import { defaultFlagSet } from '@/utils'

// Extend vitest with axe matchers
expect.extend(matchers)
Expand Down
2 changes: 1 addition & 1 deletion ppr-ui/tests/unit/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ describe('App component basic rendering normal account', () => {
it('should have no accessibility violations', async () => {
// Run the axe-core accessibility check on the component's HTML
const results = await axe(wrapper.html())
// Use the custom jest-axe matcher to check for violations
// Use the custom vitest-axe matcher to check for violations
expect(results).toHaveNoViolations()
})

Expand Down
2 changes: 1 addition & 1 deletion ppr-ui/tests/unit/Parties.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('Parties tests', () => {
expect(wrapper.findComponent(PartySummary).exists()).toBe(false)
})

it.only('does show the registering party', async () => {
it('does show the registering party', async () => {
expect(wrapper.vm.isRoleStaffSbc).toBe(false)
expect(wrapper.findComponent(RegisteringPartyChange).isVisible()).toBe(true)
})
Expand Down
2 changes: 1 addition & 1 deletion ppr-ui/tests/unit/RegistrationBar.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('RegistrationBar rppr subscribed autocomplete tests', () => {
// check autocomplete displayed
const autocomplete = wrapper.findComponent(RegistrationBarTypeAheadList)
expect(autocomplete.text()).toContain('Start a New Personal Property Registration')
// simulate selection (jest does not pickup autocomplete list)
// simulate selection (vitest does not pickup autocomplete list)
autocomplete.vm.$emit('selected', miscCrownChargeRegistrations[3])
await flushPromises()
// check emit
Expand Down
15 changes: 2 additions & 13 deletions ppr-ui/tests/unit/RegistrationsWrapper.spec.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,24 @@
// Libraries
import { nextTick } from 'vue'

import { StatusCodes } from 'http-status-codes'
import { cloneDeep } from 'lodash'
import { RegistrationsWrapper } from '@/components/common'
import { RegistrationTable } from '@/components/tables'
import { SettingOptions, TableActions } from '@/enums'
import { DraftResultIF, RegistrationSummaryIF, RegTableNewItemI } from '@/interfaces'
import { DraftResultIF, RegistrationSummaryIF } from '@/interfaces'
import { registrationTableHeaders } from '@/resources'
import {
registrationFoundDialog,
tableDeleteDialog,
tableRemoveDialog
} from '@/resources/dialogOptions'
import { axios } from '@/utils/axios-ppr'
// unit test data, etc.
import mockRouter from './MockRouter'
import {
mockedRegistration1,
mockedDraft1,
mockedDebtorNames,
mockedDraftAmend,
mockedRegistration2,
mockedUpdateRegTableUserSettingsResponse, mockedDraftFinancingStatementAll, mockedFinancingStatementAll
} from './test-data'
import { createComponent, setupIntersectionObserverMock } from './utils'
import { createComponent } from './utils'
import { useStore } from '@/store/store'
import flushPromises from 'flush-promises'
import { vi } from 'vitest'
import { BaseDialog } from '@/components/dialogs'
import { getRegistrationSummary } from '@/utils'

const store = useStore()

Expand Down
2 changes: 0 additions & 2 deletions ppr-ui/tests/unit/Stepper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ describe('Stepper - MHR Staff Registration', () => {
it('verify steps', async () => {
expectedSteps.forEach((step, index) => {
const steps = wrapper.findAll('.step')
console.log(steps.at(index).text())
expect(steps.at(index).text()).toContain(step.text.replaceAll('<br />', ''))
})
})
Expand Down Expand Up @@ -127,7 +126,6 @@ describe('Stepper - MHR Manufacturer Registration', () => {
it('verify steps', async () => {
expectedSteps.forEach((step, index) => {
const steps = wrapper.findAll('.step')
console.log(steps.at(index).text())
expect(steps.at(index).text()).toContain(step.text.replaceAll('<br />', ''))
})
})
Expand Down
36 changes: 0 additions & 36 deletions ppr-ui/tests/unit/utils/helper-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,42 +68,6 @@ export function getLastEvent (wrapper: VueWrapper<any>, name: string): any {
return events[0]
}

/**
* Utility function that mocks the `IntersectionObserver` API. Necessary for components that rely
* on it, otherwise the tests will crash. Recommended to execute inside `beforeEach`.
* @param intersectionObserverMock - Parameter that is sent to the `Object.defineProperty`
* overwrite method. `jest.fn()` mock functions can be passed here if the goal is to not only
* mock the intersection observer, but its methods.
*/
export function setupIntersectionObserverMock ({
root = null,
rootMargin = '',
thresholds = [],
disconnect = () => null,
observe = () => null,
takeRecords = () => [],
unobserve = () => null
} = {}): void {
class MockIntersectionObserver implements IntersectionObserver {
readonly root: Element | null = root
readonly rootMargin: string = rootMargin
readonly thresholds: ReadonlyArray<number> = thresholds
disconnect: () => void = disconnect
observe: (target: Element) => void = observe
takeRecords: () => IntersectionObserverEntry[] = takeRecords
unobserve: (target: Element) => void = unobserve
}

Object.defineProperty(
window,
'IntersectionObserver', {
writable: true,
configurable: true,
value: MockIntersectionObserver
}
)
}

/**
* Utility function that keeps tests looking cleaner (via string template).
* @param dataTestId - Name of 'data-test-id' attribute in the component that needs to be tested.
Expand Down
1 change: 1 addition & 0 deletions ppr-ui/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ export default defineConfig(() => {
setupFiles: './tests/setup.ts',
onConsoleLog (log) {
if (log.includes('Vue warn')) return false // Filter out Vue warnings while preserving errors and logs.
if (log.includes('AggregateError')) return false // Filter out failed network requests vs mocking them all.
}
}
}
Expand Down

0 comments on commit a499018

Please sign in to comment.