Skip to content

Commit

Permalink
chore: update test assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeed committed Jun 4, 2019
1 parent 22ada81 commit 1f8883e
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,33 @@ const foo = new Date('5/1/2017, 4:30:09 PM');
const render = (str, ctx) => fn(str)(ctx || foo);

test('tinydate', t => {
t.equal(typeof fn, 'function', 'exports a function');
t.is(typeof fn, 'function', 'exports a function');
t.end();
});

test('tinydate()', t => {
t.equal(typeof fn(''), 'function', 'returns a function');
t.is(typeof fn(''), 'function', 'returns a function');
t.end();
});

test('rendering', t => {
t.equal(render('foo'), 'foo', 'does nothing if no match');
t.equal(render('HH'), 'HH', 'does nothing if no `{}` wrappers');
t.equal(render('{MM}'), '05', 'returns numerical month');
t.equal(render('{DD}'), '01', 'returns numerical day');
t.equal(render('{YY}'), '17', 'returns partial year');
t.equal(render('{YYYY}'), '2017', 'returns full year');
t.equal(render('{HH}'), '16', 'returns full hours (24h)');
t.equal(render('{mm}'), '30', 'returns padded minutes');
t.equal(render('{ss}'), '09', 'returns seconds');
t.is(render('foo'), 'foo', 'does nothing if no match');
t.is(render('HH'), 'HH', 'does nothing if no `{}` wrappers');
t.is(render('{MM}'), '05', 'returns numerical month');
t.is(render('{DD}'), '01', 'returns numerical day');
t.is(render('{YY}'), '17', 'returns partial year');
t.is(render('{YYYY}'), '2017', 'returns full year');
t.is(render('{HH}'), '16', 'returns full hours (24h)');
t.is(render('{mm}'), '30', 'returns padded minutes');
t.is(render('{ss}'), '09', 'returns seconds');

t.equal(render('{fff}'), '000', 'returns milliseconds (default 000)');
t.equal(render('{fff}', new Date(1559607289771)), '771', 'returns milliseconds');
t.is(render('{fff}'), '000', 'returns milliseconds (default 000)');
t.is(render('{fff}', new Date(1559607289771)), '771', 'returns milliseconds');

// formats
t.equal(render('[{HH}:{mm}:{ss}]'), '[16:30:09]', 'returns formatted time string');
t.equal(render('The date is {MM}/{DD}/{YYYY}!'), 'The date is 05/01/2017!', 'returns formatted date string');
t.equal(render('Created on: [{YYYY}-{MM}-{DD} ~ {HH}:{mm}:{ss}.{fff}]'), 'Created on: [2017-05-01 ~ 16:30:09.000]', 'kitchen sink');
t.is(render('[{HH}:{mm}:{ss}]'), '[16:30:09]', 'returns formatted time string');
t.is(render('The date is {MM}/{DD}/{YYYY}!'), 'The date is 05/01/2017!', 'returns formatted date string');
t.is(render('Created on: [{YYYY}-{MM}-{DD} ~ {HH}:{mm}:{ss}.{fff}]'), 'Created on: [2017-05-01 ~ 16:30:09.000]', 'kitchen sink');

t.end();
});

0 comments on commit 1f8883e

Please sign in to comment.