Add vitest and initial tests

This commit is contained in:
Manuel
2023-03-17 22:10:00 +01:00
parent 47cb9cd5b6
commit 4a856c6267
17 changed files with 1410 additions and 56 deletions

View File

@@ -0,0 +1,26 @@
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
import { Stopwatch } from './stopwatch.tool';
describe('stopwatch', () => {
beforeEach(() => {
vi.useFakeTimers();
});
afterEach(() => {
vi.useRealTimers();
});
it.concurrent('should be elapsed time between start and current', () => {
// arrange
vi.setSystemTime(new Date(2023, 2, 26, 0, 0, 0));
const stopwatch = new Stopwatch();
// act
vi.setSystemTime(new Date(2023, 2, 26, 0, 0, 2));
const milliseconds = stopwatch.getEllapsedMilliseconds();
// assert
expect(milliseconds).toBe(2000);
});
});