Created
March 27, 2020 18:31
-
-
Save NyaGarcia/8e985e7667d88ca4b3204ce29f1f6ce8 to your computer and use it in GitHub Desktop.
Marble testing with TestScheduler and pokemon
This file contains hidden or 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 { 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