Skip to content

Commit

Permalink
chore: fix TS lint errors in #786 (#788)
Browse files Browse the repository at this point in the history
  • Loading branch information
broofa authored Aug 7, 2024
1 parent afe6232 commit 9e69599
Showing 1 changed file with 26 additions and 10 deletions.
36 changes: 26 additions & 10 deletions src/test/v4.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as assert from 'assert';
import test, { describe, mock } from 'node:test';
import v4 from '../v4.js';
import test, { describe } from 'node:test';
import native from '../native.js';
import v4 from '../v4.js';

const randomBytesFixture = Uint8Array.of(
0x10,
Expand Down Expand Up @@ -49,22 +49,38 @@ describe('v4', () => {
assert.ok(id1 !== id2);
});

test('should uses native randomUUID() if no option is passed', () => {
mock.method(native, 'randomUUID');
test('should uses native randomUUID() if no option is passed', async () => {
// TODO: `mock` is not supported until node@18, so we feature-detect it
// here. Once node@16 drops off our support matrix, we can just
// static-import it normally
const mock = (await import('node:test')).default.mock;
if (!mock) {
return;
}

assert.equal((native.randomUUID as any).mock.callCount(), 0);
const mockRandomUUID = mock.method(native, 'randomUUID');

assert.equal(mockRandomUUID.mock.callCount(), 0);
v4();
assert.equal((native.randomUUID as any).mock.callCount(), 1);
assert.equal(mockRandomUUID.mock.callCount(), 1);

mock.restoreAll();
});

test('should not use native randomUUID() if an option is passed', () => {
mock.method(native, 'randomUUID');
test('should not use native randomUUID() if an option is passed', async () => {
// TODO: `mock` is not supported until node@18, so we feature-detect it
// here. Once node@16 drops off our support matrix, we can just
// static-import it normally
const mock = (await import('node:test')).default.mock;
if (!mock) {
return;
}

const mockRandomUUID = mock.method(native, 'randomUUID');

assert.equal((native.randomUUID as any).mock.callCount(), 0);
assert.equal(mockRandomUUID.mock.callCount(), 0);
v4({});
assert.equal((native.randomUUID as any).mock.callCount(), 0);
assert.equal(mockRandomUUID.mock.callCount(), 0);

mock.restoreAll();
});
Expand Down

0 comments on commit 9e69599

Please sign in to comment.