Skip to content

Commit

Permalink
Update tests to reflect new b64 behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechilds committed May 23, 2017
1 parent 97a6430 commit 18fd7b1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions test/b64.js
Expand Up @@ -6,15 +6,18 @@ test('b64 is a function', t => {
t.is(typeof b64, 'function');
});

test('b64 calls b64[opts.method]', async t => {
const encodeResult = await b64(values.buffer, { method: 'encode' });
const decodeResult = await b64(values.base64, { method: 'decode' });
t.is(encodeResult, values.base64);
t.true(decodeResult instanceof Buffer);
t.is(decodeResult.toString(), values.string);
test('b64 calls b64.encode on buffers', async t => {
const result = await b64(values.buffer);
t.is(result, values.base64);
});

test('b64 rejects Promise if method is not \'encode\' or \'decode\'', async t => {
const error = await t.throws(b64(values.buffer));
t.is(error.message, 'opts.method must be \'encode\' or \'decode\'.');
test('b64 calls b64.decode on strings', async t => {
const result = await b64(values.base64);
t.true(result instanceof Buffer);
t.is(result.toString(), values.string);
});

test('b64 rejects Promise if input is not a buffer or string', async t => {
const error = await t.throws(b64(0));
t.is(error.message, 'input must be a buffer or string');
});

0 comments on commit 18fd7b1

Please sign in to comment.