lundi 4 juillet 2016

How do I mock a component variable/object in Angular2?

This is my template:

<ion-label stacked>goal_settings.goalname</ion-label>

I am getting the error: No value accessor for ""

This is my test:

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');
        });
    });

I think the problem is that goal_settings is wrongly mocked by me..

Aucun commentaire:

Enregistrer un commentaire