Reputation: 694
I'm unable to run unit test due error "Uncaught Error: Can't find ./first [F:/MyAppPath/scripts/first.ts] (required by F:/MyAppPath/scripts/first.spec.ts)"
I have already tried to import through require() and * as but it didn't work. also cursor get naviaget to actual class/file when I press F12 on FirstModule of below line.
import { FirstModule } from "./first";
below are my codes.
first.ts
export module FirstModule {
export class firstClass {
id:number;
name:string;
}
}
first.spec.ts
import { FirstModule } from "./first";
describe('example test', function () {
let _first
beforeEach(() => {
_first = new FirstModule.firstClass();
})
it('module defined', function () {
expect(_first).toBeDefined();
});
Logs:
Uncaught Error: Can't find ./first [F:/MyAppPath/scripts/first.ts] (required by F:/MyAppPath/scripts/first.spec.ts) at node_modules/karma-typescript/src/client/commonjs.js:13
Upvotes: 1
Views: 1420
Reputation: 1828
As error suggest, first.ts
file is missing while running first.spec.ts
through Karma.
Need add below configuration in your Karma.config.js
file.
files: [
'*.spec.ts',
'*.ts' //this thing is missing
]
Upvotes: 2