如何在Angular2中模拟组件变量/对象?

时间:2016-07-05 02:25:51

标签: unit-testing typescript angular

这是我的模板:

<ion-label stacked>{{"goal_settings.goalname" | translate }}</ion-label>

我收到错误:No value accessor for ""

这是我的测试:

describe('Goal Settings', () => {

    let tcb;
    let navParams;
    let viewController;
    let events;


    // Providers and Mock Providers

    beforeEachProviders(() => [
        TestComponentBuilder,
        HTTP_PROVIDERS,
        provide(NavParams, {useClass: MockNavParams}),
        provide(ViewController, {useClass: MockViewController}),
        provide(Events, {useClass: MockEvents}),
        provide('goal_settings', { useValue: [ {
                        goalname: "Super",
                        amount:"Super",
                        monthlypayment:"Super",
                        choosefund:"Super",
                        date:"Super",
                        guaranteelevel:"Super"
        }]}),

        provide(TranslateService, {
        useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
        deps: [Http]
        }),

        provide(TranslateLoader, {
            useFactory: (http: Http) => new TranslateStaticLoader(http, 'assets/i18n', '.json'),
            deps: [Http]
        }),
        provide(XHRBackend, { useClass: MockBackend })

    ]);

    beforeEach(inject(
        [
            TestComponentBuilder, 
            NavParams, 
            ViewController, 
            Events
        ], 
        (
            _tcb, 
            _navParams, 
            _viewController, 
            _events
        ) => { 
            tcb                 = _tcb
            navParams           = _navParams
            viewController      = _viewController
            events              = _events
    }));

    it('should contain <ion-title> directive', () => {

        return tcb.createAsync(GoalSettingsPage).then((fixture) => {

            fixture.detectChanges();
            var compiled = fixture.debugElement.nativeElement;

            expect(compiled.innerHTML).toContain('ion-title');
        });
    });

我认为问题在于goal_settings被我错误地嘲笑..

0 个答案:

没有答案