Skip to content

Instantly share code, notes, and snippets.

@caasi
Last active March 25, 2020 15:45
Show Gist options
  • Save caasi/ec4388d5c2ec33999f4803f93d5eb6b3 to your computer and use it in GitHub Desktop.
Save caasi/ec4388d5c2ec33999f4803f93d5eb6b3 to your computer and use it in GitHub Desktop.
import { of } from 'rxjs';
import { flatMap, tap } from 'rxjs/operators';
describe('containers', () => {
it('promise works', () => {
const c =
Promise.resolve(1).then(a =>
Promise.resolve(2).then(b =>
a + b
)
);
return c.then((d: number) => expect(d).toBe(3));
});
it('async/await works', async () => {
const a = await Promise.resolve(1);
const b = await Promise.resolve(2);
const c = a + b;
expect(c).toBe(3);
});
it('rx works', () => {
const c =
of(1).pipe(flatMap(a =>
of(2).pipe(flatMap(b =>
of(a + b)
))
));
c.pipe(
tap((d: number) => expect(d).toBe(3)),
);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment