mercredi 23 mars 2016

Angular2 test - not detecting changes

I'm trying to check a dropdown is shown when a boolean is switched. The boolean is an input on the component

@Component({
    selector: 'dropdown',
    directives: [NgClass],
    template: `
        <div [ngClass]="{open: open}">
        </div>
    `,
})

export class DropdownComponent {
    @Input('open') open: boolean = false;
}

And the test

it('should open', injectAsync([TestComponentBuilder], (tcb: TestComponentBuilder) => {
    return tcb.createAsync(DropdownComponent)
    .then(fixture => {
        let el = fixture.nativeElement;
        let comp: DropdownComponent = fixture.componentInstance;

        expect(el.className).toEqual('');

        comp.open = true;
        fixture.detectChanges();
        expect(el.className).toEqual('open')
    });
}));

I am guessing something different has to be done when the boolean is an @Input?

Aucun commentaire:

Enregistrer un commentaire