Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/31.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
Angular 尝试测试包含外部包的组件时出错_Angular_Testing_Karma Runner - Fatal编程技术网

Angular 尝试测试包含外部包的组件时出错

Angular 尝试测试包含外部包的组件时出错,angular,testing,karma-runner,Angular,Testing,Karma Runner,我的一个测试文件出现错误,在尝试启动Karma runner时出现以下错误: Error: Uncaught (in promise): TypeError: locale.toLowerCase is not a function at <Jasmine> at resolvePromise (node_modules/zone.js/dist/zone.js:814:31) at node_modules/z

我的一个测试文件出现错误,在尝试启动Karma runner时出现以下错误:

Error: Uncaught (in promise): TypeError: locale.toLowerCase is not a function
            at <Jasmine>
            at resolvePromise (node_modules/zone.js/dist/zone.js:814:31)
            at node_modules/zone.js/dist/zone.js:877:17
            at ZoneDelegate.invokeTask (node_modules/zone.js/dist/zone.js:421:31)
            at AsyncTestZoneSpec.onInvokeTask (node_modules/zone.js/dist/async-test.js:90:25)
Error:Uncaught(承诺中):TypeError:locale.toLowerCase不是函数
在
在resolvePromise(node_modules/zone.js/dist/zone.js:814:31)
在节点_modules/zone.js/dist/zone.js:877:17处
在ZoneDelegate.invokeTask(node_modules/zone.js/dist/zone.js:421:31)
在AsyncTestZoneSpec.onInvokeTask(node_modules/zone.js/dist/async test.js:90:25)
我不知道为什么会发生这样的事情,我一直在为此烦恼。这是正在测试的组件。如您所见,我正在使用一个名为ngxsmartmodel的外部包:

import { Component, Inject, LOCALE_ID, OnDestroy, OnInit } from "@angular/core";
import { formatCurrency } from "@angular/common";

interface SecciItemInterface {
    name: string,
    content: string
}

@Component({
    selector: "secci-modal",
    templateUrl: "migration/app/pages/payment-page/sub-sections/secci-modal/secci-modal.component.html"
})

/**
 * Display the SECCI direct debit modal
 **/
export class SecciModal implements OnInit, OnDestroy {

    public totalAncillariesTax: number = 0;
    public ancillaries = [];
    public interestRate: any;

    constructor(
        @Inject("Brand") private Brand,
        @Inject("Quote") private Quote,
        @Inject("Api") private Api,
        @Inject("Global") private Global,
        @Inject("Page") private Page,
        @Inject(LOCALE_ID) private _locale: string
    ) {

    }

    public ngOnInit(): void {
        this.getInterestRate();
        this.ancillaries = this.secciAncillaries();
    }

    /**
     * Sets the ancillaries that are to be displayed in the modal
     *
     * @returns {Array<Object>}
     */
    public secciAncillaries(): Array<Object> {
        const ancDisplayList = [];

        if (this.Quote.cars) {
            if (this.Quote.ancillaries !== 'undefined' && this.Quote.ancillaries !== null) {
                const secciSelectedList = JSON.parse(JSON.stringify(this.Quote.ancillaries.selected));
                const secciAvailableList = JSON.parse(JSON.stringify(this.Quote.ancillaries.available));

                if (this.Quote.haveComprehensive) {
                    secciSelectedList.PMWindscreenUpgradeCov = true;
                    secciAvailableList.PMWindscreenUpgradeCov = {
                        "single" : {
                            "total" : 0
                        },
                        "name" : "Windscreen Cover"
                    };
                }

                let ncbProtectionTotal = 0;
                let ncbProtectionTax = 0;
                let ncbGuaranteeTotal = 0;
                let ncbGuaranteeTax = 0;
                for (let car in this.Quote.cars) {
                    if (this.Quote.cars[car].ancillaries){
                        if (this.Quote.cars[car].ancillaries.selected["PMNCBProtectionCov"]) {
                            ncbProtectionTotal += this.Quote.cars[car].ancillaries.selected["PMNCBProtectionCov"].price;
                            ncbProtectionTax += this.Quote.cars[car].ancillaries.selected["PMNCBProtectionCov"].taxAmount;
                        }
                        if (this.Quote.cars[car].ancillaries.selected["PMNCBGuaranteedCov"]) {
                            ncbGuaranteeTotal += this.Quote.cars[car].ancillaries.selected["PMNCBGuaranteedCov"].price;
                            ncbGuaranteeTax += this.Quote.cars[car].ancillaries.selected["PMNCBGuaranteedCov"].taxAmount;
                        }
                    }
                }
                const ncbProtection = {"content" : formatCurrency(ncbProtectionTotal, this._locale, "£", "GBP"), "name" : "Protected No Claims Bonus"};
                const ncbGuarantee = {"content" : formatCurrency(ncbProtectionTotal, this._locale, "£", "GBP"), "name" : "Guaranteed No Claims Bonus"};
                for (let anc in secciSelectedList) {
                    if (secciSelectedList[anc]) {
                        let content: string;
                        if (secciAvailableList[anc].single.total == 0) {
                            content = "Included";
                        }
                        else {
                            content = formatCurrency(secciAvailableList[anc].single.total, this._locale, "£", "GBP");
                            this.totalAncillariesTax += secciAvailableList[anc].single.tax;
                        }

                        const obj: SecciItemInterface = {
                            name: secciAvailableList[anc].name,
                            content
                        };

                        ancDisplayList.push(obj);
                    }
                }
                if (ncbProtectionTotal > 0){
                    this.totalAncillariesTax += ncbProtectionTax;
                    ancDisplayList.push(ncbProtection);
                }
                if (ncbGuaranteeTotal > 0){
                    this.totalAncillariesTax += ncbGuaranteeTax;
                    ancDisplayList.push(ncbGuarantee);
                }
            }
        }

        if (this.Quote.home){
            if (this.Quote.home.ancillaries !== 'undefined' && this.Quote.home.ancillaries !== null) {
                const secciSelectedList = JSON.parse(JSON.stringify(this.Quote.ancillaries.selected));
                const secciAvailableList = JSON.parse(JSON.stringify(this.Quote.ancillaries.available));

                for (let anc in secciSelectedList){
                    if (secciSelectedList[anc]){
                        const obj: SecciItemInterface = {
                            name: secciAvailableList[anc].name,
                            content: formatCurrency(secciAvailableList[anc].single.total, this._locale, "£", "GBP")
                        };

                        this.totalAncillariesTax += secciAvailableList[anc].single.tax;
                        ancDisplayList.push(obj);
                    }
                }
            }
        }
        return ancDisplayList;
    }

    public getInterestRate(): any {
        const proratedPremium = this.Quote.response.quotePolicyTerm.proratedPremium;
        this.interestRate = ((proratedPremium !== "undefined" && proratedPremium !== null) && (proratedPremium.monthlyPremium)) ? proratedPremium.monthlyPremium.interest : "ERROR";
    }

    public ngOnDestroy(): void {

    }

    private modalHeight() {

    }
}
从“@angular/core”导入{Component,Inject,LOCALE_ID,OnDestroy,OnInit};
从“@angular/common”导入{formatCurrency}”;
接口SecciItemInterface{
名称:string,
内容:字符串
}
@组成部分({
选择器:“secci模式”,
templateUrl:“迁移/app/pages/payment page/subsections/secci modal/secci modal.component.html”
})
/**
*显示SECCI直接借记模式
**/
导出类SecciModal实现OnInit、OnDestroy{
公共totalAncillariesTax:number=0;
公共辅助设备=[];
公共利益:任何;
建造师(
@注入(“品牌”)自有品牌,
@注入(“报价”)私人报价,
@注入(“Api”)私有Api,
@注入(“全球”)私人全球,
@注入(“页面”)专用页面,
@Inject(LOCALE\u ID)private\u LOCALE:string
) {
}
public ngOnInit():void{
这个.getInterestRate();
this.accillaries=this.secciAncillaries();
}
/**
*设置要在模式中显示的辅助设备
*
*@returns{Array}
*/
public secciAncillaries():数组{
常量ANC显示列表=[];
如果(本.报价.汽车){
if(this.Quote.accillaries!='undefined'&&this.Quote.accillaries!==null){
const secciSelectedList=JSON.parse(JSON.stringify(this.Quote.accillaries.selected));
const secciAvailableList=JSON.parse(JSON.stringify(this.Quote.accillaries.available));
如果(此.Quote.haveComprehensive){
secciSelectedList.PMWindscreenUpgradeCov=true;
SecciaAvailableList.PMWindscreenUpgradeCov={
“单身”:{
“总数”:0
},
“名称”:“挡风玻璃罩”
};
}
设ncbProtectionTotal=0;
设ncbProtectionTax=0;
设ncbGuarantetotal=0;
设ncbGuaranteeTax=0;
为了(让汽车进入这个。报价。汽车){
if(this.Quote.cars[car].辅助设备){
如果(选择了this.Quote.cars[car].accillaries.if[“PMNCBProtectionCov”]){
ncbProtectionTotal+=this.Quote.cars[car].accillaries.selected[“PMNCBProtectionCov”]。price;
NCB保护税+=此.Quote.cars[car].辅助设备。所选[“PMNCB保护税”]。taxAmount;
}
如果(此.Quote.cars[car].accillaries.selected[“PMNCBGuaranteedCov”]){
NCBGuaranteTotal+=this.Quote.cars[car].accillaries.selected[“PMNCBGuaranteTotal”]。price;
NCBGuaranteTax+=this.Quote.cars[car].accillaries.selected[“PMNCBGuarantedCov”]。taxAmount;
}
}
}
const-ncbProtection={“内容”:formatCurrency(ncbProtectionTotal,this._locale,“英镑”,“英镑”),“名称”:“受保护的无索赔奖金”};
const NCBGuarante={“内容”:格式货币(ncbProtectionTotal,本._地区,“英镑”,“英镑”),“名称”:“保证无索赔奖金”};
for(让anc进入选择列表){
if(选择列表[anc]){
let内容:字符串;
if(secciAvailableList[anc].single.total==0){
content=“包括”;
}
否则{
content=formatCurrency(secciAvailableList[anc].single.total,this._locale,“英镑”,“英镑”);
this.totalAncillariesTax+=secciaAvailableList[anc].single.tax;
}
常量对象:SecciItemInterface={
姓名:SecciaAvailableList[anc]。姓名,
所容纳之物
};
显示列表推送(obj);
}
}
如果(ncbProtectionTotal>0){
此。总保险费率+=NCB保护税;
ancDisplayList.push(NCB保护);
}
如果(NCBGuaranteTotal>0){
此.totalAncillariesTax+=NCBGuaranteTax;
ancsplaylist.push(ncbguarante);
}
}
}
如果(此.Quote.home){
if(this.Quote.home.accillaries!='undefined'&&this.Quote.home.accillaries!==null){
const secciSelectedList=JSON.parse(JSON.stringify(this.Quote.accillaries.selected));
const secciAvailableList=JSON.parse(JSON.stringify(this.Quote.accillaries.available));
for(让anc进入选择列表){
if(选择列表[anc]){
常量对象:SecciItemInterface={
姓名:SecciaAvailableList[anc]。姓名,
内容:formatCurrency(secciAvailableList[anc].single.total,this._locale,“英镑”,“英镑”)
};
这是totalAncillariesTax
import { TestBed, ComponentFixture, async, inject } from "@angular/core/testing";
import { SecciModal } from "./secci-modal.component";
import {NgxSmartModalModule, NgxSmartModalService} from "ngx-smart-modal";
import { LOCALE_ID } from "@angular/core";

fdescribe("Secci Modal component", () => {
    let fixture: ComponentFixture<SecciModal>;
    let component: SecciModal;
    let mockBrand = {
        name: "name",
        ddRejectionFee: 0,
        preCollectionAdminFee: 0,
        postCollectionAdminFee: 0
    };
    let mockQuote = {
        policy: {
            monthly: {
                deposit: 0,
                numberOfPayments: 0,
                totalPremium: 0,
                installmentCharges: 0,
                apr: 0,

            },
            singleDirectDebitCost: 0,
            singleDirectDebitTax: 0
        },
        daysOfCover: 0,
        haveComprehensive: true,
        ancillaries: {
            selected: {
                PMWindscreenUpgradeCov: true
            },
            available: {

            }
        },
        cars: [
            {
                ancillaries: {
                    selected: {
                        PMNCBProtectionCov: {
                            price: 0,
                            taxAmount: 0
                        },
                        PMNCBGuaranteedCov: {
                            price: 0,
                            taxAmount: 0
                        }
                    }
                }
            }
        ],
        home: {
            ancillaries: {
                selected: {

                },
                available: {

                }
            }
        },
        response: {
            quotePolicyTerm: {
                proratedPremium: {
                    monthlyPremium: {
                        interest: 0
                    }
                }
            }
        }
    };
    let mockApi = {

    };
    let mockGlobal = {

    };
    let mockPage = {

    };

    beforeEach(async(() => {
        TestBed.configureTestingModule({
            declarations: [
                SecciModal
            ],
            imports: [
                NgxSmartModalModule.forRoot()
            ],
            providers: [
                {
                    provide: "Brand",
                    useValue: mockBrand
                },
                {
                    provide: "Quote",
                    useValue: mockQuote
                },
                {
                    provide: "Api",
                    useValue: mockApi
                },
                {
                    provide: "Global",
                    useValue: mockGlobal
                },
                {
                    provide: "Page",
                    useValue: mockPage
                },
                {
                    provide: LOCALE_ID,
                    useValue: {}
                }
            ]
        })
            .compileComponents()
            .then(() => {
                // create component and test fixture
                fixture = TestBed.createComponent(SecciModal);
                component = fixture.componentInstance;
                fixture.detectChanges();
            });
    }));

    it("secciAncillaries", (done) => {
        expect(true).toBeTruthy();
        done();
    });
});
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/observable/of';

export class NgxSmartModalServiceStub {
  getModal(id) {
    return {
      open: function () {
        return;
      },
      close: function () {
        return;
      },
      isVisible: function () {
        return;
      },
      onOpen: Observable.of({}),
      onAnyCloseEvent: Observable.of({})
    };
  }

  get(id) {
    return {
      open: function () {
        return;
      },
      close: function () {
        return;
      },
      isVisible: function () {
        return;
      },
      onOpen: Observable.of({}),
      onAnyCloseEvent: Observable.of({
        removeData() {
          return;
        }
      })
    };
  }

  setModalData() {
    return;
  }

  open() {
    return;
  }

  getModalStackCount() {
    return;
  }

  addModal() {
    return;
  }
}
beforeEach(async(() => {
  TestBed.configureTestingModule({
    imports: [
      RouterTestingModule,
      ...
    ],
    providers: [
      { provide: NgxSmartModalService, useClass: NgxSmartModalServiceStub }
    ],
  }).compileComponents();
}));