无法从测试或同一文件夹中的其他类中找到依赖项模块

问题描述 投票:0回答:2

[我们有很多ts类,它们使用常量导入文件。就像我们ts类的基本依赖项。

这是TS类的示例(请参阅ServiceBase):

import { ServiceBase } from 'src/app/service-base';
export class SomeService {

  private url = ServiceBase.ApplicationUrl;

   constructor() { }

测试文件:

    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;
        });
    });

错误:找不到模块'src/app/service-base'

如何通过测试(甚至其他ts类)实例化服务时,如何以找到ServiceBase路径的方式创建该类的实例?

测试文件与任何TS类都位于同一文件夹中。因此,如果ts类找到该ServiceBase,则测试也应该能够。

src/app/services/someservice
--some-service.ts
--some-service.test.ts
src/app/
--service-base.ts
angular typescript mocha angular9
2个回答
0
投票

您必须指出service-base文件。


0
投票

使用相对路径似乎已经解决了问题:

© www.soinside.com 2019 - 2024. All rights reserved.