|
@@ -1,4 +1,5 @@
|
|
|
-import { ComponentFixture, TestBed } from '@angular/core/testing';
|
|
|
|
|
|
|
+import { ComponentFixture, ComponentFixtureAutoDetect, TestBed} from '@angular/core/testing';
|
|
|
|
|
+import { FormsModule } from "@angular/forms";
|
|
|
|
|
|
|
|
import { CalculatorComponent } from './calculator.component';
|
|
import { CalculatorComponent } from './calculator.component';
|
|
|
|
|
|
|
@@ -8,7 +9,10 @@ describe('CalculatorComponent', () => {
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
beforeEach(async () => {
|
|
|
await TestBed.configureTestingModule({
|
|
await TestBed.configureTestingModule({
|
|
|
- declarations: [ CalculatorComponent ]
|
|
|
|
|
|
|
+ imports: [ FormsModule ],
|
|
|
|
|
+ declarations: [ CalculatorComponent ],
|
|
|
|
|
+ providers: [ { provide: ComponentFixtureAutoDetect, useValue: true }
|
|
|
|
|
+ ]
|
|
|
})
|
|
})
|
|
|
.compileComponents();
|
|
.compileComponents();
|
|
|
});
|
|
});
|
|
@@ -19,7 +23,66 @@ describe('CalculatorComponent', () => {
|
|
|
fixture.detectChanges();
|
|
fixture.detectChanges();
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ it('should bind input text to Component.value1', () => {
|
|
|
|
|
+ const dom = fixture.nativeElement;
|
|
|
|
|
+ const input = dom.querySelector('#val1');
|
|
|
|
|
+
|
|
|
|
|
+ fixture.detectChanges();
|
|
|
|
|
+ input.value = '2';
|
|
|
|
|
+ input.dispatchEvent(new Event('input'));
|
|
|
|
|
+
|
|
|
|
|
+ expect(component.value1).toBe(2);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should bind input text to Component.value2', () => {
|
|
|
|
|
+ const dom = fixture.nativeElement;
|
|
|
|
|
+ const input = dom.querySelector('#val2');
|
|
|
|
|
+
|
|
|
|
|
+ fixture.detectChanges();
|
|
|
|
|
+ input.value = '2';
|
|
|
|
|
+ input.dispatchEvent(new Event('input'));
|
|
|
|
|
+
|
|
|
|
|
+ expect(component.value2).toBe(2);
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should display when Component.value1 changes', () => {
|
|
|
|
|
+ const dom = fixture.nativeElement;
|
|
|
|
|
+ const input = dom.querySelector('#val1');
|
|
|
|
|
+
|
|
|
|
|
+ component.value1 = 3;
|
|
|
|
|
+
|
|
|
|
|
+ fixture.detectChanges();
|
|
|
|
|
+ fixture.whenStable().then(() => {
|
|
|
|
|
+ expect(input.value).toBe('3');
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should display when Component.value2 changes', () => {
|
|
|
|
|
+ const dom = fixture.nativeElement;
|
|
|
|
|
+ const input = dom.querySelector('#val2');
|
|
|
|
|
+
|
|
|
|
|
+ component.value2 = 3;
|
|
|
|
|
+
|
|
|
|
|
+ fixture.detectChanges();
|
|
|
|
|
+ fixture.whenStable().then(() => {
|
|
|
|
|
+ expect(input.value).toBe('3');
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ it('should display result when Component.result changes', () => {
|
|
|
|
|
+ const dom = fixture.nativeElement;
|
|
|
|
|
+ const resultElement = dom.querySelector('#result');
|
|
|
|
|
+
|
|
|
|
|
+ component.result = 37;
|
|
|
|
|
+
|
|
|
|
|
+ fixture.detectChanges();
|
|
|
|
|
+ fixture.whenStable().then(() => {
|
|
|
|
|
+ expect(resultElement.textContent).toContain('37');
|
|
|
|
|
+ });
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
it('should create', () => {
|
|
it('should create', () => {
|
|
|
expect(component).toBeTruthy();
|
|
expect(component).toBeTruthy();
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
});
|
|
});
|