I have the following structure : src folder with file1.ts spec folder(same level as src - siblings) with file1.spec.ts I try to run typescript Jasmine tests file1.ts looks like this :
export module moduleName {
export class className {
public doSomething(a: string): string {
return a;
}
}
}
file1.spec.ts looks like this :
const aliasFile = require('../src/file1');
describe("tests", function () {
let f;
beforeEach(function () {
f = new aliasFile.className();
});
it("should run", function () {
const result = f.doSomething('aaa');
expect(result).toEqual('aaa');
});
});
when I ran this test I get this result :
- tests should run
- TypeError: aliasFile.className is not a constructor
- TypeError: Cannot read property 'doSomething' of undefined
what is the proper way to define the test?
You can try replacing
requiremethod with aliasedimportkeyword like this: