This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyComponent () { | |
this.message = 'foo'; | |
} | |
MyComponent.prototype.ngOnInit = function () { | |
this.message = 'bar'; | |
}; | |
MyComponent.prototype.sayHello = function () { | |
this.message = 'Hello World'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, Type } from '@angular/core'; | |
const compσηιψ = (μ: Component, λ: Function): Type<any> => | |
Component(μ).Class(Object.assign({ constructor: λ, λ })); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Minimal redux for local states | |
* @link https://spin.atomicobject.com/2017/07/24/redux-action-pattern-typescript/ | |
*/ | |
export interface ReducerFn<S, A> { | |
(state: S, action: A): S | |
} | |
export interface Action<T> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TestBed, async, inject } from '@angular/core/testing'; | |
import { HttpClientModule, HttpRequest, HttpParams } from '@angular/common/http'; | |
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | |
import { HttpClientFeatureService } from './http-client-feature.service'; | |
describe(`HttpClientFeatureService`, () => { | |
beforeEach(() => { | |
TestBed.configureTestingModule({ | |
imports: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Injectable } from '@angular/core'; | |
import { HttpClient, HttpHeaders, HttpParams, HttpResponse } from '@angular/common/http'; | |
import { Observable } from 'rxjs/Observable'; | |
/** This class implements some features that should be tested. */ | |
@Injectable() | |
export class HttpClientFeatureService { | |
constructor( | |
private http: HttpClient |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe(`FakeHttpClientResponses`, () => { | |
it(`should respond with fake data`, async(inject([HttpClient, HttpTestingController], | |
(http: HttpClient, backend: HttpTestingController) => { | |
http.get('/foo/bar').subscribe((next) => { | |
expect(next).toEqual({ baz: '123' }); | |
}); | |
backend.match({ | |
url: '/foo/bar', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe(`FakeHttpClientResponses`, () => { | |
it(`should expect a GET /foo/bar`, async(inject([HttpClient, HttpTestingController], | |
(http: HttpClient, backend: HttpTestingController) => { | |
http.get('/foo/bar').subscribe(); | |
backend.expectOne({ | |
url: '/foo/bar', | |
method: 'GET' | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { NgModule } from '@angular/core'; | |
import { HttpClientModule } from '@angular/common/http'; | |
import { FooBarService } from './foo-bar.service'; | |
@NgModule({ | |
imports: [ HttpClientModule ], | |
providers: [ FooBarService ] | |
}) | |
export class FooBarModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { TestBed, async, inject } from '@angular/core/testing'; | |
import { HttpClientModule, HttpClient } from '@angular/common/http'; | |
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | |
describe(`FakeHttpClientResponses`, () => { | |
beforeEach(() => { | |
// 0. set up the test environment | |
TestBed.configureTestingModule({ | |
imports: [ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { browser, by, element, until } from 'protractor'; | |
export class AppPage { | |
public navigateTo() { | |
return browser.get('/'); | |
} | |
public enterSearchInput(text: string) { | |
return element(by.css('input[aria-label="search"]')) |