|
|
@@ -2,6 +2,8 @@ import { ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '@angular/c
|
|
|
import { FormsModule } from "@angular/forms";
|
|
|
|
|
|
import { CalculatorComponent } from './calculator.component';
|
|
|
+import {Component} from "@angular/core";
|
|
|
+import {HttpClientModule} from "@angular/common/http";
|
|
|
|
|
|
describe('CalculatorComponent', () => {
|
|
|
let component: CalculatorComponent;
|
|
|
@@ -9,8 +11,8 @@ describe('CalculatorComponent', () => {
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
await TestBed.configureTestingModule({
|
|
|
- imports: [ FormsModule ],
|
|
|
- declarations: [ CalculatorComponent ],
|
|
|
+ imports: [ FormsModule, HttpClientModule ],
|
|
|
+ declarations: [ CalculatorComponent, MockCalculatorService ],
|
|
|
providers: [ { provide: ComponentFixtureAutoDetect, useValue: true }
|
|
|
]
|
|
|
})
|
|
|
@@ -45,40 +47,36 @@ describe('CalculatorComponent', () => {
|
|
|
expect(component.value2).toBe(2);
|
|
|
});
|
|
|
|
|
|
- it('should display when Component.value1 changes', () => {
|
|
|
+ it('should display when Component.value1 changes', async () => {
|
|
|
const dom = fixture.nativeElement;
|
|
|
const input = dom.querySelector('#val1');
|
|
|
|
|
|
component.value1 = 3;
|
|
|
|
|
|
fixture.detectChanges();
|
|
|
- fixture.whenStable().then(() => {
|
|
|
- expect(input.value).toBe('3');
|
|
|
- });
|
|
|
+ await fixture.whenStable();
|
|
|
+ expect(input.value).toBe('3');
|
|
|
});
|
|
|
|
|
|
- it('should display when Component.value2 changes', () => {
|
|
|
+ it('should display when Component.value2 changes', async () => {
|
|
|
const dom = fixture.nativeElement;
|
|
|
const input = dom.querySelector('#val2');
|
|
|
|
|
|
component.value2 = 3;
|
|
|
|
|
|
fixture.detectChanges();
|
|
|
- fixture.whenStable().then(() => {
|
|
|
- expect(input.value).toBe('3');
|
|
|
- });
|
|
|
+ await fixture.whenStable();
|
|
|
+ expect(input.value).toBe('3');
|
|
|
});
|
|
|
|
|
|
- it('should display result when Component.result changes', () => {
|
|
|
+ it('should display result when Component.result changes', async () => {
|
|
|
const dom = fixture.nativeElement;
|
|
|
const resultElement = dom.querySelector('#result');
|
|
|
|
|
|
component.result = 37;
|
|
|
|
|
|
fixture.detectChanges();
|
|
|
- fixture.whenStable().then(() => {
|
|
|
- expect(resultElement.textContent).toContain('37');
|
|
|
- });
|
|
|
+ await expect(resultElement.textContent).toContain('37');
|
|
|
});
|
|
|
|
|
|
it('should create', () => {
|
|
|
@@ -86,3 +84,10 @@ describe('CalculatorComponent', () => {
|
|
|
});
|
|
|
|
|
|
});
|
|
|
+
|
|
|
+@Component({
|
|
|
+ selector: 'CalculatorService',
|
|
|
+ template: ''
|
|
|
+})
|
|
|
+class MockCalculatorService {
|
|
|
+}
|