Skip to content

Commit

Permalink
test: adds tests for into
Browse files Browse the repository at this point in the history
  • Loading branch information
rafamel committed Apr 8, 2020
1 parent 1dcbc4f commit 8f72242
Showing 1 changed file with 84 additions and 0 deletions.
84 changes: 84 additions & 0 deletions test/into.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { into } from '~/into';

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

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

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

describe(`async`, () => {
test(`returns a promise`, () => {
const promise = into.async('foo');

expect(promise).toBeInstanceOf(Promise);
});
test(`works wo/ a function`, async () => {
const promise = into.async('foo');

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

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

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

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

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

0 comments on commit 8f72242

Please sign in to comment.