Skip to content

Commit

Permalink
Simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cressie176 committed Dec 19, 2024
1 parent 158d0cd commit 741d8ce
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/index.test.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
const assert = require('assert');
const { ok, strictEqual: eq, throws } = require('assert');
const { describe, it } = require('zunit');
const { fake, real } = require('..');

describe('clocks', () => {

it('fake clock should default to groundhog day', () => {
assert.equal(fake.now(), 1454410800000);
eq(fake.now(), 1454410800000);
});

it('fake clock should fixed time', () => {
assert.equal(fake.fix(1469563181761).now(), 1469563181761);
assert.equal(fake.fix(new Date(1469563181761)).now(), 1469563181761);
assert.equal(fake.fix(new Date(1469563181761).toISOString()).now(), 1469563181761);
eq(fake.fix(1469563181761).now(), 1469563181761);
eq(fake.fix(new Date(1469563181761)).now(), 1469563181761);
eq(fake.fix(new Date(1469563181761).toISOString()).now(), 1469563181761);
});

it('fake clock should reject attempts to fix time to an invalid value', () => {
assert.throws(() => {
throws(() => {
fake.fix('foo');
}, /Invalid Date: foo/);
});

it('real clock should use correct time', () => {
assert.ok(Math.abs(real.now() - Date.now()) < 100);
ok(Math.abs(real.now() - Date.now()) < 100);
});
});

0 comments on commit 741d8ce

Please sign in to comment.