Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix TS lint errors in #786 #788

Merged
merged 4 commits into from
Aug 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading