Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/460.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/42.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Angular 2测试无法加载自定义包_Javascript_Node.js_Unit Testing_Angular_Typescript - Fatal编程技术网

Javascript Angular 2测试无法加载自定义包

Javascript Angular 2测试无法加载自定义包,javascript,node.js,unit-testing,angular,typescript,Javascript,Node.js,Unit Testing,Angular,Typescript,我遵循官方的angular2指南对现有项目进行测试 我使用了一个自定义库,当我运行应用程序时,它工作得很好。但在测试运行的情况下,我在控制台中得到一个错误: "__zone_symbol__zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/downloadjs/download.js\n\tError: XHR error (404 Not Found) loading node_

我遵循官方的angular2指南对现有项目进行测试

我使用了一个自定义库,当我运行应用程序时,它工作得很好。但在测试运行的情况下,我在控制台中得到一个错误:

"__zone_symbol__zoneAwareStack": "Error: (SystemJS) XHR error (404 Not Found) loading node_modules/downloadjs/download.js\n\tError: XHR error (404 Not Found) loading node_modules/downloadjs/download.js\n\tError loading node_modules/downloadjs/download.js as \"downloadjs\" from app/utilities/file-handler.utility.js"
我使用了
npm install downloadjs
来获取该工具

file-handler.utility.js如下所示:

import {Injectable} from "@angular/core";
import downloadjs=require("downloadjs");
@Injectable()
export class FileHandler{

  public static download(fileToDownload: any) {
    downloadjs(fileToDownload, "filename.txt" ,"text/plain");
  }   
}
我已在同一文件夹中创建了defs.spec.ts文件:

declare module 'downloadjs'{
    function download(data:any, strFileName:string, strMimeType:string):void;

        export = download;
}
并将路径添加到systemjs.config.js:

 // other libraries
      'rxjs':                      'npm:rxjs',
      'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js',
      'downloadjs': 'npm:downloadjs/download.js'
因此,这在
npm start中运行良好。

但正如指南所述,在创建1st.spec.ts之后:

describe('1st tests', () => {
  it('true is true', () => expect(true).toBe(true));
});

这会抛出我粘贴在顶部的错误。谢谢你抽出时间

问题与defs.spec.ts位置有关。我们决定使用现有的angular 2模板,与之集成后,测试现在可以正常工作。

如果您使用npm手动安装库,您是否尝试过全局安装:npm install-g downloadJS尝试过,同样的错误。您能告诉我“angular 2模板”是什么意思吗?请添加工作代码,以便对希望在angular 2应用程序中使用downloadjs的用户有所帮助。我们将整个项目移动到一个新的框架中,名为。现在,我使用Angular CLI来创建项目,而这个问题从那时起就没有发生过(我们现在使用Angular 5)