We utilize multiple TypeScript classes that import a file containing constants which serve as a foundational dependency for our TypeScript classes.
Here is an example of the TypeScript class (refer to ServiceBase):
import { ServiceBase } from 'src/app/service-base';
export class SomeService {
private url = ServiceBase.ApplicationUrl;
constructor() { }
The test file:
import * as chai from 'chai';
import { SomeService } from './some.service';
describe('SomeService', () => {
let service: SomeService;
beforeEach(() => {
chai.should();
service = new SomeService()
});
it('should be created', () => {
let expected: any = (service == undefined);
expected.should.be.false;
});
});
Error:
Cannot find module 'src/app/service-base'
How can I ensure the class instance is able to locate the correct path for ServiceBase when instantiated through a test (or any other TypeScript class)?
The test file shares the same folder location with any of the TypeScript classes. Therefore, if the TypeScript class can access ServiceBase, the test should also be able to do so.
src/app/services/someservice
--some-service.ts
--some-service.test.ts
src/app/
--service-base.ts