Skip to content

Instantly share code, notes, and snippets.

@dherges
dherges / protractor.conf.js
Created August 4, 2017 07:47
Angular, Protractor, Cucumber
// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts
exports.config = {
allScriptsTimeout: 11000,
capabilities: {
'browserName': 'chrome'
},
directConnect: true,
@dherges
dherges / example.feature
Last active August 4, 2017 06:48
Angular, Protractor, Cucumber
Feature: Search
As a developer using Angular
I need to look-up classes and guidelines
So that I can concentrate on building awesome applications
Scenario: Type in a search-term
Given I am on the angular.io site
When I type "foo" into the search input field
Then I should see some results in the search overlay
@dherges
dherges / reactive-conf.feature
Last active August 8, 2017 07:29
WITHDRAWN - Unfortunately, I cannot attend! This was a Proposal for a lightning talk at ReactiveConf 2017
Feature: ReactiveConf Lightning Talks are awesome
As a visitor of https://reactiveconf.com/
I want to learn about Cucumber and Protractor
So that I can test my awesome applications like my users do
Scenario: Curiosity is killing me
Given this proposal for #ReactiveConf 2017 open call for Lightning talks
When you star this summary on GitHub
Then you can go and listen to the talk
But you can also retweet: https://twitter.com/davidh_23/status/889051659711774720
@dherges
dherges / lru-cache.ts
Last active November 17, 2025 20:56
Simple LRU Cache in TypeScript
class LruCache<T> {
private values: Map<string, T> = new Map<string, T>();
private maxEntries: number = 20;
public get(key: string): T {
const hasKey = this.values.has(key);
let entry: T;
if (hasKey) {
// peek the entry, re-insert for LRU strategy
@dherges
dherges / number.component.spec.ts
Created June 19, 2017 12:08
Angular Testing Snippets: Component (1)
import { TestBed, async, fakeAsync, tick } from '@angular/core/testing';
import { NumberComponent } from './number.component';
describe('NumberComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ NumberComponent ],
}).compileComponents();
}));
@dherges
dherges / number.component.ts
Last active June 19, 2017 12:09
Angular Testing Snippets: Component (1)
import { Component, EventEmitter, Input, Output } from '@angular/core';
/**
* A very dumb replacement for `<input type="number">`.
*
* Usage: `<my-number [value]="99" (onValueChanges)="changed($event)></my-number>
*/
@Component({
selector: 'my-number',
template: '<input type="text" [value]="value" (change)="onChange($event.target.value)">'
@dherges
dherges / feature.service.spec.ts
Created May 18, 2017 18:19
Angular Testing Snippets: Services over HTTP (4)
describe(`FeatureService`, () => {
/** ... set up ... **/
it(`should emit 'true' for 200 Ok`,
async(inject([ FeatureService, MockBackend ],
(service: FeatureService, mockBackend: MockBackend) => {
// 1. prepare fake response from `MockBackend`
mockBackend.connections.subscribe((c: MockConnection) => {
@dherges
dherges / feature.service.spec.ts
Last active May 18, 2017 18:00
Angular Testing Snippets: Services over HTTP
describe(`FeatureService`, () => {
/** ... set up ... **/
it(`should emit 'false' for 401 Unauthorized`,
async(inject([ FeatureService, MockBackend ],
(service: FeatureService, mockBackend: MockBackend) => {
// 0. prepare fake response from `MockBackend`
mockBackend.connections.subscribe((c: MockConnection) => {
// 2a. expect `FeatureSerivice` to make a proper request
@dherges
dherges / feature.service.spec.ts
Last active May 18, 2017 17:47
Angular Testing Snippets: Services over HTTP
import { Injector } from '@angular/core';
import { async, inject, TestBed } from '@angular/core/testing';
import { Http, HttpModule, Request, RequestMethod, RequestOptions, Response,
ResponseOptions, URLSearchParams, XHRBackend } from '@angular/http';
import { MockBackend, MockConnection } from '@angular/http/testing';
describe('FeatureService', () => {
let backend: MockBackend;
//setup
@dherges
dherges / feature.service.ts
Last active May 18, 2017 07:21
Angular Testing Snippets: Services over HTTP
/** This class implements some features that should be tested. */
@Injectable()
export class FeatureService {
constructor(
private http: Http
) {}
login(user: string, password: string): Observable<boolean> {
let body = new URLSearchParams();