簡體   English   中英

Angular 2 測試無法加載自定義包

[英]Angular 2 test cannot load custom package

我正在按照官方的 angular2 指南對現有項目進行測試。

我使用自定義庫downloadjs ,當我運行應用程序時它工作得很好。 但是在測試運行的情況下,我在控制台中收到錯誤消息:

"__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.運行得很好npm start.

但正如指南所述,在用這個創建 1st.spec.ts 之后:

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

這會引發我粘貼在頂部的錯誤。 感謝您的時間!

問題與 defs.spec.ts 位置有關。 我們決定使用現有的 angular 2 模板,在與它集成后,測試現在可以工作了。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM