Skip to content

Instantly share code, notes, and snippets.

@Huluvu424242
Created April 19, 2022 18:12
Show Gist options
  • Save Huluvu424242/e665800e0b607c828926f6aa67f33178 to your computer and use it in GitHub Desktop.
Save Huluvu424242/e665800e0b607c828926f6aa67f33178 to your computer and use it in GitHub Desktop.
rxjs marble test problem of pipe integration
// Ein Beispiel für ein Filter der von Date.now abhängt
// Der Filter lässt sich als Unittest separat prüfen
//
// Problem: Wie kann ich ein die komplette pipe als
// Integrationtest mit mable time test utils prüfen?
//
// Der Kode ist als unit test formuliert, damit er in idea
// direkt ausführbar ist. Es ist aber natürlich kein Test
// sondern die Problemstellung.
//
import {it} from "mocha";
import {filter, from, take, timer} from "rxjs";
import {switchMap} from "rxjs/operators";
describe('Example', () => {
it('its no test, its only for excecution', (done) => {
const myNow = Date.now();
console.log('###' + new Date(myNow));
const feeds = [{url: "a", pubtime: new Date(myNow - 3000)}, {url: "b", pubtime: new Date(myNow - 2000)}]
timer(0, 1000).pipe(
switchMap(
() => from(feeds)
),
filter(
(feed) => (Date.now() - feed.pubtime.getTime() > 3000)
),
take(3)
).subscribe({
next: (value) => console.log("#" + value.url + "(" + value.pubtime + ")"),
error: (err) => console.error("!!!" + err),
complete: () => done()
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment