vendredi 20 octobre 2017

Issues testing an Angular component

I have a component with the following initialization

ngOnInit() {
    this.transactionForm.get('type').valueChanges.subscribe(transType => {
            if (transType === 'xx') {
                this.transactionForm.patchValue({
                    subTotal: 0
                });
                console.log('done', this.transactionForm.value);
            }
        });
    }

And I am trying to write the following test:

it('should ...', () => {
            fixture.detectChanges();
            const expectedSubTotal = 0;
            comp.transactionForm.patchValue({
                type: 'xx',
                subTotal: 42
            });
            fixture.detectChanges();
            console.log('getting');
            const actual = comp.transactionForm.get('subTotal').value; // Does not get 0 - gets 42 instead
            expect(actual).toBe(expectedSubTotal);
        });

The console.logs all print the right value but I cannot seem to get this test to pass. What am I missing?

Aucun commentaire:

Enregistrer un commentaire