From ce3c41f788e6f577e8f46cdf77d5e508aacd405d Mon Sep 17 00:00:00 2001 From: Brandon Clayton <bclayton@usgs.gov> Date: Mon, 16 Dec 2024 14:22:29 -0700 Subject: [PATCH] set input --- package-lock.json | 1 - package.json | 1 - projects/nshmp-apps/jest.config.ts | 15 ++++++++++----- projects/nshmp-apps/setup-jest.ts | 12 +++++++++--- .../building-code-control.component.spec.ts | 4 ++++ .../disagg-contributors.component.spec.ts | 3 +++ .../disagg-data/disagg-data.component.spec.ts | 3 +++ .../disagg-summary.component.spec.ts | 3 +++ 8 files changed, 32 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index 010ee7478..15ef62697 100644 --- a/package-lock.json +++ b/package-lock.json @@ -81,7 +81,6 @@ "gts": "^6.0.2", "husky": "^9.1.7", "jest": "^29.7.0", - "jest-environment-jsdom": "^29.7.0", "jest-fail-on-console": "^3.3.1", "jest-junit": "^16.0.0", "jest-preset-angular": "^14.4.2", diff --git a/package.json b/package.json index cde0c884b..cc7df8bc3 100644 --- a/package.json +++ b/package.json @@ -105,7 +105,6 @@ "gts": "^6.0.2", "husky": "^9.1.7", "jest": "^29.7.0", - "jest-environment-jsdom": "^29.7.0", "jest-fail-on-console": "^3.3.1", "jest-junit": "^16.0.0", "jest-preset-angular": "^14.4.2", diff --git a/projects/nshmp-apps/jest.config.ts b/projects/nshmp-apps/jest.config.ts index 394a5fb64..4fae2fdfb 100644 --- a/projects/nshmp-apps/jest.config.ts +++ b/projects/nshmp-apps/jest.config.ts @@ -6,17 +6,22 @@ const config: Config.InitialOptions = { coverageReporters: ['text-summary', 'html'], globalSetup: 'jest-preset-angular/global-setup', maxWorkers: '80%', - moduleNameMapper: pathsToModuleNameMapper( - {'projects/*': ['*']}, - {prefix: '<rootDir>/..'}, - ), + moduleNameMapper: { + d3: '<rootDir>/../../node_modules/d3/dist/d3.min.js', + ...pathsToModuleNameMapper({'projects/*': ['*']}, {prefix: '<rootDir>/..'}), + }, preset: 'jest-preset-angular', reporters: ['default', 'jest-junit'], roots: ['..'], setupFilesAfterEnv: ['<rootDir>/setup-jest.ts'], testPathIgnorePatterns: ['<rootDir>/cypress'], transformIgnorePatterns: [ - 'node_modules/(?!.*\\.mjs$|d3|d3-*|delaunator|robust-predicates|internmap|@ghsc/nshmp-utils-ts/node_modules/d3-format|yaml|change-case)', + `node_modules/( + ?!.*\\.mjs$| + yaml| + change-case| + @ghsc/nshmp-utils-ts/node_modules/d3-format + )/`, ], }; diff --git a/projects/nshmp-apps/setup-jest.ts b/projects/nshmp-apps/setup-jest.ts index 195bbea19..b29124854 100644 --- a/projects/nshmp-apps/setup-jest.ts +++ b/projects/nshmp-apps/setup-jest.ts @@ -1,9 +1,13 @@ -import 'jest-preset-angular/setup-jest'; - import failOnConsole from 'jest-fail-on-console'; +import {setupZoneTestEnv} from 'jest-preset-angular/setup-env/zone'; // Make Jest test fail on console.error and warn -failOnConsole(); +failOnConsole({ + // https://github.com/primefaces/primeng/issues/14085 + silenceMessage: message => { + return !(message === 'Error: Could not parse CSS stylesheet'); + }, +}); Object.defineProperty(window, 'CSS', {value: null}); Object.defineProperty(window.URL, 'createObjectURL', {value: function () {}}); @@ -27,3 +31,5 @@ Object.defineProperty(document.body.style, 'transform', { }; }, }); + +setupZoneTestEnv(); diff --git a/projects/nshmp-apps/src/app/designmaps/rtgm/components/building-code-control/building-code-control.component.spec.ts b/projects/nshmp-apps/src/app/designmaps/rtgm/components/building-code-control/building-code-control.component.spec.ts index 881b7520d..718ebfbe9 100644 --- a/projects/nshmp-apps/src/app/designmaps/rtgm/components/building-code-control/building-code-control.component.spec.ts +++ b/projects/nshmp-apps/src/app/designmaps/rtgm/components/building-code-control/building-code-control.component.spec.ts @@ -4,6 +4,7 @@ import {provideNoopAnimations} from '@angular/platform-browser/animations'; import {provideRouter} from '@angular/router'; import {BuildingCodeControlComponent} from './building-code-control.component'; +import {FormControl} from '@angular/forms'; describe('BuildingCodeControlComponent', () => { let component: BuildingCodeControlComponent; @@ -21,6 +22,9 @@ describe('BuildingCodeControlComponent', () => { fixture = TestBed.createComponent(BuildingCodeControlComponent); component = fixture.componentInstance; + + fixture.componentRef.setInput('control', new FormControl()); + fixture.detectChanges(); }); diff --git a/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-contributors/disagg-contributors.component.spec.ts b/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-contributors/disagg-contributors.component.spec.ts index d2e5e96e1..4f1485792 100644 --- a/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-contributors/disagg-contributors.component.spec.ts +++ b/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-contributors/disagg-contributors.component.spec.ts @@ -24,6 +24,9 @@ describe('DisaggContributorsComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(DisaggContributorsComponent); component = fixture.componentInstance; + + fixture.componentRef.setInput('componentData', undefined); + fixture.detectChanges(); }); diff --git a/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-data/disagg-data.component.spec.ts b/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-data/disagg-data.component.spec.ts index d5c0d7072..4fcb0d885 100644 --- a/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-data/disagg-data.component.spec.ts +++ b/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-data/disagg-data.component.spec.ts @@ -21,6 +21,9 @@ describe('DisaggDataComponent', () => { fixture = TestBed.createComponent(DisaggDataComponent); component = fixture.componentInstance; + + fixture.componentRef.setInput('componentData', undefined); + fixture.detectChanges(); }); diff --git a/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-summary/disagg-summary.component.spec.ts b/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-summary/disagg-summary.component.spec.ts index f64909fb4..bc00687f9 100644 --- a/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-summary/disagg-summary.component.spec.ts +++ b/projects/nshmp-apps/src/app/hazard/disagg/components/disagg-summary/disagg-summary.component.spec.ts @@ -24,6 +24,9 @@ describe('DisaggSummaryComponent', () => { beforeEach(() => { fixture = TestBed.createComponent(DisaggSummaryComponent); component = fixture.componentInstance; + + fixture.componentRef.setInput('componentData', undefined); + fixture.detectChanges(); }); -- GitLab