Angular 2testing不能加载自定义包
我正在按照官方的angular2指南对现有项目进行testing。
我使用自定义库, downloadjs ,当我运行该应用程序时,它工作得很好。 但是在testing运行的情况下,在控制台中出现错误:
"__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"); } }
我在同一个文件夹中创build了一个defs.spec.ts文件:
declare module 'downloadjs'{ function download(data:any, strFileName:string, strMimeType:string):void; export = download; }
并将path添加到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.
运行得很好npm start.
但是如指南所述,在创build1st.spec.ts之后:
describe('1st tests', () => { it('true is true', () => expect(true).toBe(true)); });
这会抛出我粘贴在顶部的错误。 感谢您的时间!
问题与defs.spec.ts位置有关。 我们决定使用一个现有的angular度2模板,并与它合并后,testing现在工作。