Skip to content

Commit

Permalink
use better delay test (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
beuluis authored Jul 10, 2023
1 parent 72b4173 commit 771c125
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions test/util.test.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@
import { C, delay } from '../src/util';

describe('C', () => {
it('should return character code for simple characters', () => {
expect(C('a')).toBe(97);
describe('util', () => {
beforeEach(() => {
jest.useFakeTimers().setSystemTime(new Date('2023-01-01'));
});

it('should return character code for special characters', () => {
expect(C('\n')).toBe(10);
afterEach(() => {
jest.clearAllMocks();
});

it('should throw when code cannot be found', () => {
expect(() => C('')).toThrow(Error);
describe('C', () => {
it('should return character code for simple characters', () => {
expect(C('a')).toBe(97);
});

it('should return character code for special characters', () => {
expect(C('\n')).toBe(10);
});

it('should throw when code cannot be found', () => {
expect(() => C('')).toThrow(Error);
});
});
});

describe('delay', () => {
it('should delay for milliseconds', async () => {
expect.assertions(1);
const start = Date.now();
describe('delay', () => {
it('should delay for milliseconds', async () => {
expect.assertions(1);
const waitTime = 100;

const delayPromise = delay(waitTime);

await delay(100);
jest.advanceTimersByTime(waitTime);

expect(Date.now() - start).toBeGreaterThanOrEqual(100);
await expect(delayPromise).resolves.toBeUndefined();
});
});
});

1 comment on commit 771c125

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage report

St.
Category Percentage Covered / Total
🟢 Statements 99.37% 472/475
🟢 Branches 96.08% 98/102
🟢 Functions 100% 75/75
🟢 Lines 99.36% 464/467

Test suite run success

124 tests passing in 4 suites.

Report generated by 🧪jest coverage report action from 771c125

Please sign in to comment.