Skip to content

Commit

Permalink
test: comments from issue #270
Browse files Browse the repository at this point in the history
  • Loading branch information
satanTime committed Jan 10, 2021
1 parent 68a8751 commit 7da5fc1
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions tests/issue-270/test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { Component, Injectable } from '@angular/core';
import { TestBed } from '@angular/core/testing';
import { MockProvider, MockRender } from 'ng-mocks';
import { Subject } from 'rxjs';

export const EMPTY = new Subject<any>();
EMPTY.complete();

@Injectable()
class TargetService {
public stream$ = EMPTY;
}

@Component({
selector: 'target',
template: `{{ service.stream$ | async }}`,
})
class TargetComponent {
public constructor(public readonly service: TargetService) {}
}

describe('issue-270', () => {
const mock = {
stream$: new Subject<number>(),
};

afterAll(() => mock.stream$.complete());

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TargetComponent],
providers: [MockProvider(TargetService, mock)],
});
});

it('mocks the property', () => {
const fixture = MockRender(TargetComponent);

// default template
expect(fixture.nativeElement.innerHTML).toEqual(
'<target></target>',
);

// emit 1
mock.stream$.next(1);
fixture.detectChanges();
expect(fixture.nativeElement.innerHTML).toEqual(
'<target>1</target>',
);

// emit 2
mock.stream$.next(2);
fixture.detectChanges();
expect(fixture.nativeElement.innerHTML).toEqual(
'<target>2</target>',
);
});
});

0 comments on commit 7da5fc1

Please sign in to comment.