Skip to content

Commit

Permalink
Merge pull request #1003 from CruGlobal/update-jest
Browse files Browse the repository at this point in the history
[no-jira] Update Jest to v29
  • Loading branch information
canac authored Feb 13, 2023
2 parents f4ee531 + f15df60 commit 641a329
Show file tree
Hide file tree
Showing 11 changed files with 1,708 additions and 1,319 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: actions/setup-node@v2
with:
node-version: 12
node-version: 16.10.0

- name: Install Dependencies
run: yarn install --immutable --immutable-cache
Expand All @@ -36,7 +36,7 @@ jobs:

- uses: actions/setup-node@v2
with:
node-version: 12
node-version: 16.10.0

- name: Install Dependencies
run: yarn install --immutable --immutable-cache
Expand All @@ -58,7 +58,7 @@ jobs:

- uses: actions/setup-node@v2
with:
node-version: 12
node-version: 16.10.0

- name: Install Dependencies
run: yarn install --immutable --immutable-cache
Expand Down
2 changes: 1 addition & 1 deletion .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
nodejs 16.0.0
nodejs 16.10.0
yarn 1.22.17
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
],
restoreMocks: true,
setupFilesAfterEnv: [
'<rootDir>/jest/setupAngularMocks.js',
'angular',
'angular-mocks',
'jest-date-mock',
Expand All @@ -17,6 +18,7 @@ module.exports = {
modulePaths: [
'<rootDir>/src'
],
testEnvironment: 'jsdom',
transform: {
'^.+\\.js?$': 'babel-jest',
'^.+\\.html$': '<rootDir>/jest/htmlTransform.js'
Expand Down
2 changes: 1 addition & 1 deletion jest/htmlTransform.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ module.exports = {
resource: path.basename(filename)
}
const result = ngTemplateLoader.call(webpackContext, `\`${src}\``)
return `${result}; module.exports = "${path.basename(filename)}"`
return { code: `${result}; module.exports = "${path.basename(filename)}"` }
}
}
2 changes: 2 additions & 0 deletions jest/setupAngularMocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// angular-mocks won't setup mocking unless Jasmine or Karma is defined, so pretend like it is
window.jasmine = true
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@
"copy-webpack-plugin": "^5.0.4",
"css-loader": "^3.2.0",
"html-loader": "^0.5.5",
"jest": "^24.9.0",
"jest": "^29.4.2",
"jest-date-mock": "^1.0.7",
"jest-environment-jsdom": "^29.4.2",
"mini-css-extract-plugin": "^0.8.0",
"moment-locales-webpack-plugin": "^1.1.0",
"ngtemplate-loader": "^2.0.1",
Expand Down
12 changes: 6 additions & 6 deletions src/app/designationEditor/designationEditor.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ describe('Designation Editor', function () {
let modalPromise
beforeEach(inject((_$q_) => {
modalPromise = _$q_.defer()
spyOn($ctrl.$uibModal, 'open').and.returnValue({ result: modalPromise.promise })
jest.spyOn($ctrl.$uibModal, 'open').mockReturnValue({ result: modalPromise.promise })
$ctrl.designationContent = designationSecurityResponse
}))

Expand All @@ -343,11 +343,11 @@ describe('Designation Editor', function () {
]

expect($ctrl.$uibModal.open).toHaveBeenCalled()
expect($ctrl.$uibModal.open.calls.argsFor(0)[0].resolve.designationNumber()).toEqual(designationSecurityResponse.designationNumber)
expect($ctrl.$uibModal.open.calls.argsFor(0)[0].resolve.campaignPage()).toBeUndefined()
expect($ctrl.$uibModal.open.calls.argsFor(0)[0].resolve.photos()).toEqual(photos)
expect($ctrl.$uibModal.open.calls.argsFor(0)[0].resolve.photoLocation()).toEqual('secondaryPhotos')
expect($ctrl.$uibModal.open.calls.argsFor(0)[0].resolve.selectedPhoto()).toEqual(selectedPhotos)
expect($ctrl.$uibModal.open.mock.calls[0][0].resolve.designationNumber()).toEqual(designationSecurityResponse.designationNumber)
expect($ctrl.$uibModal.open.mock.calls[0][0].resolve.campaignPage()).toBeUndefined()
expect($ctrl.$uibModal.open.mock.calls[0][0].resolve.photos()).toEqual(photos)
expect($ctrl.$uibModal.open.mock.calls[0][0].resolve.photoLocation()).toEqual('secondaryPhotos')
expect($ctrl.$uibModal.open.mock.calls[0][0].resolve.selectedPhoto()).toEqual(selectedPhotos)
})

it('should have empty selectedPhotos', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/app/designationEditor/photoModal/photoModal.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ describe('Designation Editor Photo', function () {

it('uploadComplete', function () {
let getPhotosPromise = $q.defer()
spyOn($ctrl.designationEditorService, 'getPhotos').and.returnValue(getPhotosPromise.promise)
jest.spyOn($ctrl.designationEditorService, 'getPhotos').mockReturnValue(getPhotosPromise.promise)

$ctrl.uploadComplete()
$timeout.flush()
Expand Down
22 changes: 12 additions & 10 deletions src/app/profile/profile.component.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,35 +205,37 @@ describe('ProfileComponent', function () {
})

describe('initTitles()', () => {
let expectedTitles;
beforeEach(() => {
$ctrl.donorDetails = {
name: {},
'spouse-name': {}
}
this.expectedTitles = angular.copy(titles)
this.expectedTitles[''] = ''
expectedTitles = angular.copy(titles)
expectedTitles[''] = ''
})

it('should load all the normal titles', () => {
$ctrl.initTitles()

expect($ctrl.availableTitles).toEqual(this.expectedTitles)
expect($ctrl.availableTitles).toEqual(expectedTitles)
})

it('should additional leacy titles if they are in use in donorDetails', () => {
$ctrl.donorDetails.name.title = 'Alderman'
$ctrl.donorDetails['spouse-name'].title = 'Prof'
$ctrl.initTitles()
this.expectedTitles.Alderman = 'Alderman'
this.expectedTitles.Prof = 'Professor'
expectedTitles.Alderman = 'Alderman'
expectedTitles.Prof = 'Professor'

expect($ctrl.availableTitles).toEqual(this.expectedTitles)
expect($ctrl.availableTitles).toEqual(expectedTitles)
})
})

describe('updateDonorDetails()', () => {
let donorDetails;
beforeEach(() => {
this.donorDetails = {
donorDetails = {
name: {
'family-name': 'Lname',
'given-name': 'Fname'
Expand All @@ -246,18 +248,18 @@ describe('ProfileComponent', function () {
})

it('should update donor details', () => {
$ctrl.donorDetails = this.donorDetails
$ctrl.donorDetails = donorDetails
jest.spyOn($ctrl.profileService, 'updateProfileDonorDetails').mockReturnValue(Observable.of(''))
jest.spyOn($ctrl, 'updateEmail').mockImplementation(() => {})
$ctrl.updateDonorDetails()

expect($ctrl.profileService.updateProfileDonorDetails).toHaveBeenCalledWith(this.donorDetails)
expect($ctrl.profileService.updateProfileDonorDetails).toHaveBeenCalledWith(donorDetails)
expect($ctrl.donorDetailsForm.$setPristine).toHaveBeenCalled()
expect($ctrl.updateEmail).toHaveBeenCalled()
})

it('should update donor details while adding a spouse', () => {
$ctrl.donorDetails = this.donorDetails
$ctrl.donorDetails = donorDetails
$ctrl.addingSpouse = true
jest.spyOn($ctrl.profileService, 'updateProfileDonorDetails').mockReturnValue(Observable.of(''))
jest.spyOn($ctrl, 'updateEmail').mockImplementation(() => {})
Expand Down
13 changes: 7 additions & 6 deletions src/common/services/hateoasHelper.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,9 @@ describe('HATEOAS helper service', function () {
})

describe('mapChildZoomElements', () => {
let element, zoomString, childZoomStrings;
beforeEach(() => {
this.element = {
element = {
_code: [
{
someKey: 'someValue'
Expand All @@ -171,12 +172,12 @@ describe('HATEOAS helper service', function () {
}
]
}
this.zoomString = 'lineitems:element'
this.childZoomStrings = ['lineitems:element:code', 'lineitems:element:rates[]', 'lineitems:element:paymentmeans:creditcard']
zoomString = 'lineitems:element'
childZoomStrings = ['lineitems:element:code', 'lineitems:element:rates[]', 'lineitems:element:paymentmeans:creditcard']
})

it('should take an element and map the child zoom strings to keys', () => {
expect(self.hateoasHelperService.mapChildZoomElements(this.element, this.zoomString, this.childZoomStrings)).toEqual({
expect(self.hateoasHelperService.mapChildZoomElements(element, zoomString, childZoomStrings)).toEqual({
code: {
someKey: 'someValue'
},
Expand All @@ -201,9 +202,9 @@ describe('HATEOAS helper service', function () {
})

it('should return undefined if the zoom isn\'t found', () => {
this.childZoomStrings = ['lineitems:element:code2', 'lineitems:element:rates2[]']
childZoomStrings = ['lineitems:element:code2', 'lineitems:element:rates2[]']

expect(self.hateoasHelperService.mapChildZoomElements(this.element, this.zoomString, this.childZoomStrings)).toEqual({
expect(self.hateoasHelperService.mapChildZoomElements(element, zoomString, childZoomStrings)).toEqual({
_code: [
{
someKey: 'someValue'
Expand Down
Loading

0 comments on commit 641a329

Please sign in to comment.