-
Notifications
You must be signed in to change notification settings - Fork 70
/
home-component.ng-mocks.spec.ts
45 lines (37 loc) · 1.34 KB
/
home-component.ng-mocks.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { NO_ERRORS_SCHEMA } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { MockComponent } from 'ng-mocks';
import { CounterComponent } from '../counter/counter.component';
import { HomeComponent } from './home.component';
describe('HomeComponent with ng-mocks', () => {
let fixture: ComponentFixture<HomeComponent>;
let component: HomeComponent;
let counter: CounterComponent;
beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [HomeComponent, MockComponent(CounterComponent)],
schemas: [NO_ERRORS_SCHEMA],
}).compileComponents();
fixture = TestBed.createComponent(HomeComponent);
component = fixture.componentInstance;
fixture.detectChanges();
const counterEl = fixture.debugElement.query(By.directive(CounterComponent));
counter = counterEl.componentInstance;
});
it('renders an independent counter', () => {
expect(counter).toBeTruthy();
});
it('passes a start count', () => {
expect(counter.startCount).toBe(5);
});
it('listens for count changes', () => {
spyOn(console, 'log');
const count = 5;
counter.countChange.emit(count);
expect(console.log).toHaveBeenCalledWith(
'countChange event from CounterComponent',
count,
);
});
});