Skip to content

Instantly share code, notes, and snippets.

@NyaGarcia
Created March 27, 2020 18:31
Show Gist options
  • Save NyaGarcia/8e985e7667d88ca4b3204ce29f1f6ce8 to your computer and use it in GitHub Desktop.
Save NyaGarcia/8e985e7667d88ca4b3204ce29f1f6ce8 to your computer and use it in GitHub Desktop.
Marble testing with TestScheduler and pokemon
import { TestScheduler } from "rxjs/testing";
import { filter, map } from "rxjs/operators";
describe("Awesome testing with Marble Diagrams", () => {
const scheduler = new TestScheduler((actual, expected) => {
expect(actual).toEqual(expected);
});
it("should filter non-Water type pokemon and add attack property", () => {
scheduler.run(({ cold, expectObservable }) => {
const values = {
a: { name: "Bulbasur", type: "Grass" },
b: { name: "Charmander", type: "Fire" },
c: { name: "Squirtle", type: "Water" }
};
const marbleDiagram = "-a-b-c|";
const pokemon$ = cold(marbleDiagram, values);
const expectedMarbleDiagram = "-----c|";
const expectedValues = {
c: { name: "Squirtle", type: "Water", attack: 30 }
};
const result = pokemon$.pipe(
filter(({ type }) => type === "Water"),
map(pokemon => ({ ...pokemon, attack: 30 }))
);
expectObservable(result).toBe(expectedMarbleDiagram, expectedValues);
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment