Skip to content

Instantly share code, notes, and snippets.

View cartant's full-sized avatar

Nicholas Jamieson cartant

View GitHub Profile
return this.http.get<Something>("https://api.some.com/things/1").pipe(
map(this.extractSomeProperty),
catchError(this.handleError)
);
import { expect } from "chai";
import { fakeSchedulers } from "rxjs-marbles/mocha";
import { timer } from "rxjs";
import * as sinon from "sinon";
describe("timer", () => {
let clock: sinon.SinonFakeTimers;
beforeEach(() => {
import * as React from "react";
import { componentFromStream, createEventHandler } from "recompose";
import { from } from "rxjs";
import { debounceTime, distinctUntilChanged, map, startWith } from "rxjs/operators";
export const SomeComponent = () => {
const { handler, stream } = createEventHandler();
const SearchingComponent = componentFromStream(props => from(stream).pipe(
map(event => event.target.value),
debounceTime(400),
import { mount } from "enzyme";
import * as React from "react";
import { fakeSchedulers } from "rxjs-marbles/jest";
import { SomeComponent } from "./SomeComponent";
describe("SomeComponent", () => {
beforeEach(() => jest.useFakeTimers());
it("should indicate when searching", fakeSchedulers(advance => {
import { Component, Input, OnInit, OnDestroy } from "@angular/core";
import { debounceTime, distinctUntilChanged, switchMapTo, takeUntil } from "rxjs/operators";
import { observe } from "rxjs-observe";
@Component({
selector: "some-component",
template: "<span>Some useless component that writes to the console</span>"
})
class SomeComponent implements OnInit, OnDestroy {
@Input() public name: string;
import { observe } from "rxjs-observe";
const instance = { name: "Alice" };
const { observables, proxy } = observe(instance);
observables.name.subscribe(value => console.log(name));
proxy.name = "Bob";
it('should indicate when searching', fakeSchedulers(() => {
const fixture = TestBed.createComponent(SomeComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;
const input = compiled.querySelector('input');
expect(compiled.querySelector('.searching')).toBeNull();
fixture.componentInstance.form.patchValue({ term: 'foo' });
fixture.detectChanges();
expect(compiled.querySelector('.searching')).toBeNull();
tick(400);
import { TestBed, async } from '@angular/core/testing';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { fakeSchedulers } from 'rxjs-marbles/jasmine/angular';
import { SomeComponent } from './some.component';
describe("SomeComponent", () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [SomeComponent],
import { Component } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { Observable } from 'rxjs';
import { debounceTime, distinctUntilChanged, pluck } from 'rxjs/operators';
@Component({
selector: 'some-component',
template: `
<form [formGroup]="form">
<input formControlName="term" type="text">
import { combineLatest, Observable } from "rxjs";
import { takeUntil } from "rxjs/operators";
declare const a: Observable<number>;
declare const b: Observable<number>;
declare const notifier: Observable<any>;
const c = a.pipe(
o => combineLatest(o, b),
takeUntil(notifier)