Skip to content

Commit

Permalink
test: adds tests for pipe
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 8, 2020
1 parent 6e6ae73 commit 1dcbc4f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 3 deletions.
3 changes: 0 additions & 3 deletions test/index.test.ts

This file was deleted.

70 changes: 70 additions & 0 deletions test/pipe.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { pipe } from '~/pipe';

describe(`sync`, () => {
test(`works w/ 1 function`, () => {
const fn = pipe((value: string) => value + 'bar');
expect(fn('foo')).toBe('foobar');
});
test(`works w/ a number of functions`, () => {
const fn = pipe(
(value: string) => value + 'bar',
(value) => ({ value }),
(value) => ({ value: value.value + 'baz' })
);

expect(fn('foo')).toEqual({ value: 'foobarbaz' });
});
test(`works w/ intermediary undefined values`, () => {
const fn = pipe(
(value: string) => value + 'bar',
undefined,
(value) => ({ value }),
undefined,
undefined,
(value) => ({ value: value.value + 'baz' }),
undefined
);

expect(fn('foo')).toEqual({ value: 'foobarbaz' });
});
});

describe(`async`, () => {
test(`returns a promise`, () => {
const fn = pipe.async((value: string) => value + 'bar');

expect(fn('foo')).toBeInstanceOf(Promise);
});
test(`works w/ 1 sync function`, async () => {
const fn = pipe.async((value: string) => value + 'bar');

await expect(fn('foo')).resolves.toBe('foobar');
});
test(`works w/ 1 async function`, async () => {
const fn = pipe.async(async (value: string) => value + 'bar');

await expect(fn('foo')).resolves.toBe('foobar');
});
test(`works w/ a number of functions`, async () => {
const fn = pipe.async(
async (value: string) => value + 'bar',
(value) => ({ value }),
async (value) => ({ value: value.value + 'baz' })
);

await expect(fn('foo')).resolves.toEqual({ value: 'foobarbaz' });
});
test(`works w/ intermediary undefined values`, async () => {
const fn = pipe.async(
async (value: string) => value + 'bar',
undefined,
(value) => ({ value }),
undefined,
undefined,
async (value) => ({ value: value.value + 'baz' }),
undefined
);

await expect(fn('foo')).resolves.toEqual({ value: 'foobarbaz' });
});
});

0 comments on commit 1dcbc4f

Please sign in to comment.