I got a full test fixture that failed. Looking at the console log, it contained the following error message:
Access to XMLHttpRequest at 'ng:///CompanyVehicleGridComponent.js'
from origin 'http://localhost:9876' has been blocked by CORS policy:
Cross origin requests are only supported for protocol schemes: http,
data, chrome, chrome-extension, chrome-untrusted, https.
I am using PrimeNG controls in an Angular 11 application. I am using a PrimeNG grid that displays and deletes rows. Then in the grid, clicking on create and edit button will popup a PrimeNG modal dialog. I find this composition of components an interesting testing challenge. The following illustrates the grid component:
<!-- File: company-vehicle-grid.component.html -->
<div *ngIf='companyvehicles !== undefined'>
<p-table id='companyvehicles-grid' [value]='companyvehicles'
[totalRecords]='totalRecords' dataKey='VehicleId'
[rows]='5' [paginator]='true' [rowsPerPageOptions]='[5,10,50]'>
...
</p-table>
</div>
<!-- modal edit windows -->
<app-company-vehicle-detail-window [companyvehicle]='windowCompanyVehicleInput'
(closeWin)='closeWin($event)'></app-company-vehicle-detail-window>
...
<!-- End of company-vehicle.grid.component.html -->
This error appeared in the grid test structure. Running the following tesing directive:
ng test --source-map=false
Did not help. I removed the company-vehicle-detail-window and the error disappeared, showing that the issue is due to changes in the modal dialog window. In the process of implementing the PrimeNG modal dialog, I changed some service calls that caused the error and needs to be added to the mock spy service of the grid tests, so the modal dialog can get through the constructor and the ngOnInit.
Additionally, one thing I plan on changing is that when I was developing the detail window, I had the describe set to limit tests to test only the one structure as follows:
fdescribe( 'CompanyVehicleDetailWindowComponent', ( ) => {
I will now set the grid to also test the grid form at the same time, so I will see the error when the change was made.