Skip to content

Instantly share code, notes, and snippets.

View wescopeland's full-sized avatar

Wes Copeland wescopeland

View GitHub Profile
@wescopeland
wescopeland / entity.service.spec.ts
Created June 16, 2019 13:17
entity.service.spec.ts
import { SpectatorService, SpyObject, createService } from '@netbasal/spectator/jest';
import { of } from 'rxjs';
import { AwesomeEntityStore } from './entity.store';
import { EntityDataService } from './entity-data.service';
import { EntityService } from './entity.service';
describe('Service: EntityService', () => {
let dataService: SpyObject<EntityDataService>;
let store: SpyObject<AwesomeEntityStore>;
@wescopeland
wescopeland / entity.service.ts
Created June 16, 2019 13:17
entity.service.ts
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { tap } from 'rxjs/operators';
import { AwesomeEntity } from './awesome-entity.model';
import { AwesomeEntityStore } from './entity.store';
import { EntityDataService } from './entity-data.service';
@Injectable()
export class EntityService {
@wescopeland
wescopeland / entity-data.service.ts
Created June 16, 2019 13:11
entity-data.service.ts
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { AwesomeEntity } from './awesome-entity.model';
@Injectable()
export class EntityDataService {
constructor(private _http: HttpClient) {}
getEntities() {
@wescopeland
wescopeland / entity-data.service.spec.ts
Created June 16, 2019 13:11
entity-data.service.spec.ts
import { createHTTPFactory, SpectatorHTTP } from '@netbasal/spectator/jest';
import { HTTPMethod } from '@netbasal/spectator';
import { EntityDataService } from './entity-data.service';
describe('Service: EntityDataService', () => {
const httpService: () => SpectatorHTTP<EntityDataService> = createHTTPFactory<
EntityDataService
>(EntityDataService);
@wescopeland
wescopeland / awesome-entity.model.ts
Created June 16, 2019 13:10
awesome-entity.model.ts
export interface AwesomeEntity {
id: number;
}
@wescopeland
wescopeland / notification.service.spec.ts
Created June 16, 2019 13:05
notification service spec
import { SpectatorService, SpyObject, createService } from '@netbasal/spectator/jest';
import { MatSnackBar } from '@angular/material/snack-bar';
import { NotificationService } from './notification.service';
describe('Service: NotificationService', () => {
let snackBar: SpyObject<MatSnackBar>;
let spectator: SpectatorService<NotificationService> = createService({
service: NotificationService,
@wescopeland
wescopeland / notification.service.ts
Created June 16, 2019 13:03
notification service
import { Injectable } from '@angular/core';
import { MatSnackBar } from '@angular/material/snack-bar';
@Injectable({ providedIn: 'root' })
export class NotificationService {
constructor(private _snackBar: MatSnackBar) {}
notify(message: string, duration = 7000): void {
this._snackBar.open(message, 'CLOSE', { duration });
}
@wescopeland
wescopeland / stateful.component.spec.ts
Created June 15, 2019 19:59
Stateful Component Testing w/ Spectator
import { Spectator, SpyObject, createTestComponentFactory } from '@netbasal/spectator/jest';
import { of } from 'rxjs';
import { StatefulComponent } from './stateful.component';
import { AwesomeEntitiesQuery } from './+state';
describe('Component: StatefulComponent', () => {
let query: SpyObject<AwesomeEntitiesQuery>;
let spectator: Spectator<StatefulComponent>;
@wescopeland
wescopeland / presentational-button.component.spec.ts
Last active June 15, 2019 19:51
Presentational Button Component Spectator Test
import { Spectator, createTestComponentFactory } from '@netbasal/spectator/jest';
import { PresentationalButtonComponent as PBComponent } from './presentational-button.component';
describe('Component: PresentationalButtonComponent', () => {
let spectator: Spectator<PBComponent>;
const createComponent = createTestComponentFactory<PBComponent>({
component: PBComponent
});
@wescopeland
wescopeland / entity.service.spec.ts
Last active June 15, 2019 19:52
entity service unit testing example
import { SpectatorService, SpyObject, createService } from '@netbasal/spectator/jest';
import { of } from 'rxjs';
import { AwesomeEntityStore } from './entity.store';
import { EntityDataService } from './entity-data.service';
import { EntityService } from './entity.service';
describe('Service: EntityService', () => {
let dataService: SpyObject<EntityDataService>;
let store: SpyObject<AwesomeEntityStore>;