Skip to content

Commit

Permalink
begin tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mhkeller committed Mar 19, 2023
1 parent 66f8792 commit cc7cdb7
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/utils/formatTime.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ export default function formatTime (milliseconds) {
const oneHour = 3600000;
const oneMinute = 60000;
const oneSecond = 1000;
const seconds = 0;
const minutes = 0;
const hours = 0;
const result = '';

let seconds = 0;
let minutes = 0;
let hours = 0;
let result = '';
if (milliseconds === 0) {
return '0ms';
}
Expand Down Expand Up @@ -69,4 +70,4 @@ export default function formatTime (milliseconds) {
}

return result;
};
}
30 changes: 30 additions & 0 deletions test/formatTimestamp.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/* globals describe it */
import assert from 'assert';

import fn from '../src/utils/formatTimestamp.js';

const name = 'formatTimestamp';

const timesToTest = [
{ args: [new Date(2017, 0, 1)], expected: '00:00:00.00' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 0)], expected: '11:33:30.00' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 50)], expected: '11:33:30.05' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 45)], expected: '11:33:30.05' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 40)], expected: '11:33:30.04' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 100)], expected: '11:33:30.10' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 350)], expected: '11:33:30.35' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 340)], expected: '11:33:30.34' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 356)], expected: '11:33:30.36' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 900)], expected: '11:33:30.90' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 990)], expected: '11:33:30.99' },
{ args: [new Date(2017, 0, 1, 11, 33, 30, 998)], expected: '11:33:30.99' }
];

describe(name, () => {
timesToTest.forEach(t => {
it(`should match expected ${t.args[0]}`, () => {
const actual = fn(t.args[0]);
assert.equal(actual, t.expected);
});
});
});
10 changes: 0 additions & 10 deletions test/simple.test.js

This file was deleted.

0 comments on commit cc7cdb7

Please sign in to comment.