Мой тест для компонента ниже продолжает сбой с сообщением об ошибке:
HeadlessChrome 78.0.3882 (Windows 10.0.0) LoginButtonGroupComponent : should have option to sign in with Google FAILED
Failed: Cannot read property 'innerText' of null
Однако он проходит для теста should have option to sign in with email address
. Есть идеи, что не так?
Тест
import { LoginButtonGroupComponent } from './login-button-group.component';
import { FormsModule } from '@angular/forms';
import { async, inject, TestBed } from '@angular/core/testing';
import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import { TestStore } from '../../../core/core.spec';
import { State } from '../../../core/store/auth/auth.reducer';
import { Store } from '@ngrx/store';
describe('LoginButtonGroupComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [FormsModule],
providers: [
{ provide: Store, useClass: TestStore }
],
declarations: [LoginButtonGroupComponent]
}).compileComponents().then(() => {
});
}));
describe(':', () => {
let fixture, app;
let store: TestStore<State>;
beforeEach((inject([Store], (testStore: TestStore<State>) => {
store = testStore;
store.setState({user: null, error: null});
fixture = TestBed.createComponent(LoginButtonGroupComponent);
app = fixture.debugElement.componentInstance;
})));
afterEach(() => {
fixture.destroy();
app = null;
});
it('should create the component', async(() => {
expect(app).toBeTruthy();
}));
it('should have option to sign in with Google', async(() => {
expect(document.getElementById('googleSignIn').innerText.trim()).toBe('Sign in with Google');
}));
it('should have option to sign in with Facebook', async(() => {
expect(document.getElementById('facebookSignIn').innerText.trim()).toBe('Sign in with Facebook');
}));
it('should have option to sign in with email address', async(() => {
expect(document.getElementById('emailSignIn').innerText.trim()).toBe('or use your email address');
}));
});
});
Компонент
<p [ngClass]="setButtonAlignment(position)">
<button (click)="googleSignIn()" *ngIf="!(isMobile | async)?.matches" class="btn btn-label btn-google"
type="button">
<label id="googleSignIn">
<fa-icon [icon]="['fab', 'google']" size="xs"></fa-icon>
</label> Sign in with Google
</button>
<button (click)="mobileGoogleSignIn()" *ngIf="(isMobile | async)?.matches" class="btn btn-label btn-google"
type="button">
<label id="mobileGoogleSignIn">
<fa-icon [icon]="['fab', 'google']" size="xs"></fa-icon>
</label> Sign in with Google
</button>
<button (click)="facebookSignIn()" *ngIf="!(isMobile | async)?.matches" class="btn btn-label btn-facebook"
type="button">
<label id="facebookSignIn">
<fa-icon [icon]="['fab', 'facebook-f']" size="xs"></fa-icon>
</label> Sign in with Facebook
</button>
<button (click)="mobileFacebookSignIn()" *ngIf="(isMobile | async)?.matches" class="btn btn-label btn-facebook"
type="button">
<label id="mobileFacebookSignIn">
<fa-icon [icon]="['fab', 'facebook-f']" size="xs"></fa-icon>
</label> Sign in with Facebook
</button>
</p>
<p [ngClass]="setButtonAlignment(position)">
<small>
<a class="text-muted small-2" id="emailSignIn" routerLink="/register">or use your email address <fa-icon
[icon]="['fas', 'long-arrow-alt-right']" size="xs"></fa-icon>
</a>
</small>
</p>