Implement spec for ErrorMessageComponent
Some checks failed
continuous-integration/drone the build failed
Some checks failed
continuous-integration/drone the build failed
This commit is contained in:
parent
4bfce46f70
commit
4d4f8b2992
1 changed files with 37 additions and 10 deletions
|
@ -1,25 +1,52 @@
|
||||||
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
|
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
|
||||||
|
|
||||||
import { ErrorMessageComponent } from './error-message.component';
|
import {ErrorMessageComponent} from './error-message.component';
|
||||||
|
import {Component, ViewChild} from '@angular/core';
|
||||||
|
import {Step} from '../step';
|
||||||
|
|
||||||
|
@Component({
|
||||||
|
template: '<app-error-message [step]="step"></app-error-message>'
|
||||||
|
})
|
||||||
|
class TestHostComponent {
|
||||||
|
public step: Step = new Step(42);
|
||||||
|
@ViewChild(ErrorMessageComponent)
|
||||||
|
public sutComponent: ErrorMessageComponent;
|
||||||
|
}
|
||||||
|
|
||||||
describe('ErrorMessageComponent', () => {
|
describe('ErrorMessageComponent', () => {
|
||||||
let component: ErrorMessageComponent;
|
let testHostComponent: TestHostComponent;
|
||||||
let fixture: ComponentFixture<ErrorMessageComponent>;
|
let testHostFixture: ComponentFixture<TestHostComponent>;
|
||||||
|
|
||||||
beforeEach(async(() => {
|
beforeEach(async(() => {
|
||||||
TestBed.configureTestingModule({
|
TestBed.configureTestingModule({
|
||||||
declarations: [ ErrorMessageComponent ]
|
declarations: [
|
||||||
|
ErrorMessageComponent,
|
||||||
|
TestHostComponent
|
||||||
|
]
|
||||||
})
|
})
|
||||||
.compileComponents();
|
.compileComponents();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
fixture = TestBed.createComponent(ErrorMessageComponent);
|
testHostFixture = TestBed.createComponent(TestHostComponent);
|
||||||
component = fixture.componentInstance;
|
testHostComponent = testHostFixture.componentInstance;
|
||||||
fixture.detectChanges();
|
testHostFixture.detectChanges();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create', () => {
|
it('should create', () => {
|
||||||
expect(component).toBeTruthy();
|
expect(testHostComponent.sutComponent).toBeTruthy();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should display an error message', () => {
|
||||||
|
// arrange
|
||||||
|
testHostComponent.step.error = true;
|
||||||
|
testHostComponent.step.message = 'This is an error message';
|
||||||
|
|
||||||
|
// act
|
||||||
|
testHostFixture.detectChanges();
|
||||||
|
|
||||||
|
// assert
|
||||||
|
expect(testHostComponent.sutComponent.step.error).toBeTruthy();
|
||||||
|
expect(testHostComponent.sutComponent.step.message).toEqual('This is an error message');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue