Skip to content

Instantly share code, notes, and snippets.

import { Injectable } from '@angular/core';
import { ReplaySubject } from 'rxjs/ReplaySubject';
@Injectable()
export class PopupService {
private popupDialog = new ReplaySubject<{popupEvent: string, component?, options?: {}}>();
public popupDialog$ = this.popupDialog.asObservable();
import { PopupService } from './popup.service';
import { SignInComponent } from '../components/signin/signin.component';
describe('PopupService', () => {
let service: PopupService;
// create PopupService instance
beforeEach(() => { service = new PopupService(); });
// we need 'done' to avoid test finishing before date was received
it('subscribe for opening works', (done: DoneFn) => {
service.open(SignInComponent, [{title: 'Попап заголовок', message: 'Успешно'}]);
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: '<h1> Welcome to {{ title }}!</h1>',
styleUrls: ['./app.component.css']
})
export class AppComponent {
title = 'app';
}
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [
AppComponent
],
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(AppComponent);
comp = fixture.componentInstance;
});
it('should create the comp', => {
expect(comp).toBeTruthy();
});
it(`should have as title 'app'`, () => {
expect(comp.title).toEqual('app');
});
it('should render title in a h1 tag', () => {
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelector('h1').textContent)
.toContain('Welcome to app!');
});
export class AppComponent {
constructor(private popup: PopupService) { }
title = 'app';
}
TestBed.configureTestingModule({
declarations: [
AppComponent
],
providers: [PopupService]
});
const popupServiceStub = {
open: () => {}
};