Tests don't run in Angular 16 using Jasmine/Karma
Command
test
Is this a regression?
- [X] Yes, this behavior used to work in the previous version
The previous version in which this bug was not present was
15
Description
The project compiles well, and the tests worked in version 15 of Angular. After running ng test I am receiving the following error:
ng-virtual-main.js!=!data:text/javascript;base64 ...Unknown string like token - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): ...Unknown string like token s missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
Minimal Reproduction
After running ng test I am receiving the following error:
ng-virtual-main.js!=!data:text/javascript;base64 ...Unknown string like token - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): ...Unknown string like token s missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.
Exception or Error
`ng-virtual-main.js!=!data:text/javascript;base64 ...Unkown string like token - Error: Module build failed (from ./node_modules/@ngtools/webpack/src/ivy/index.js): ...Unkown string like token s missing from the TypeScript compilation. Please make sure it is in your tsconfig via the 'files' or 'include' property.`
Your Environment
npm ls @ngtools/webpack
`└─┬ @angular-devkit/[email protected]
└── @ngtools/[email protected]`
ng version
`Angular CLI: 16.2.4
Node: 18.15.0
Package Manager: npm 9.5.0
OS: linux x64
Angular: 16.2.7
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router
Package Version
--------------------------------------------------------------
@angular-devkit/architect 0.1602.4
@angular-devkit/build-angular 16.2.4
@angular-devkit/core 16.2.4
@angular-devkit/schematics 16.2.4
@angular/cdk 16.2.6
@angular/cli 16.2.4
@angular/material 16.2.6
@angular/material-date-fns-adapter 16.2.6
@schematics/angular 16.2.4
rxjs 7.5.7
typescript 4.9.3
zone.js 0.13.3
`
Anything else relevant?
No response
This seems like a bug but we'll need to look at a reproduction to find and fix the problem. Can you setup a minimal repro please?
You can read here why this is needed. A good way to make a minimal repro is to create a new app via ng new repro-app and adding the minimum possible code to show the problem. Then you can push this repository to github and link it here.
This might be related to your directory structure so its really important to get an accurate repro to diagnose this.
I haven't managed to reproduce the error in another project yet, but when I decoded the 'unknown string' I received something like this in case it helps:
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting,
} from '@angular/platform-browser-dynamic/testing';
// Initialize the Angular testing environment.
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting(), {
errorOnUnknownElements: true,
errorOnUnknownProperties: true
});
Hello @alan-agius4 here is the small app where you can get the error when running ng test . I hope it is of great help.
https://github.com/apangr/repro-app
This seems to be caused by the allowJs tsconfig option.
well, in my project I have some .js files and I will have them until I have time to create an npm package, if I exclude them from the test can it work? or is it necessary to remove the allowJs option and files?
It is necessary to remove the allowJs option until a fix is provided.
ok thanks for your help
I have also come across this issue. Will it be fixed anytime soon?
+1
Same issue....
FYI, changing allowJs from true to false fixed it for me. Fortunately, I didn't have any JS files and don't remember why it was there to begin with.
Luckily I already migrated away from Karma several years ago to Jest. Which works much better now and also works well with Angular. Angular also has a builder for that: @angular-builders/jest:run.