diff --git a/package.json b/package.json index 0ab2c2a..feacdd1 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ }, "scripts": { "build": "del distribution && tsc", - "test": "tsc --noEmit && xo && ava && node test/test-node.js", + "test": "tsc --noEmit && xo && ava", "prepare": "npm run build" }, "files": [ diff --git a/source/index.ts b/source/index.ts index aa68c81..f5c8fdd 100644 --- a/source/index.ts +++ b/source/index.ts @@ -418,7 +418,7 @@ export function isBuffer(value: unknown): value is NodeBuffer { } export function isClass(value: unknown): value is Class { - return isFunction(value) && /^class(\s|{)/.test(value.toString()); + return isFunction(value) && /^class(\s+|{)/.test(value.toString()); } export function isDataView(value: unknown): value is DataView { diff --git a/test/test-node.js b/test/test-node.js deleted file mode 100644 index e742b87..0000000 --- a/test/test-node.js +++ /dev/null @@ -1,15 +0,0 @@ -import assert from 'node:assert'; -import {test} from 'node:test'; -import is, {assert as isAssert} from '../distribution/index.js'; - -// Note: this test is separate from the rest of the tests, as it requires -// preserving whitespace. The tsimp modifies the source and does not -// properly preserve the intended test case -test('is.class', () => { - const minifiedClass = class{}; // eslint-disable-line keyword-spacing - assert.ok(is.class(minifiedClass)); - - assert.doesNotThrow(() => { - isAssert.class(minifiedClass); - }); -}); diff --git a/test/test.ts b/test/test.ts index 523bf11..4da5723 100644 --- a/test/test.ts +++ b/test/test.ts @@ -1086,9 +1086,13 @@ test('is.asyncIterable', t => { test('is.class', t => { class Foo {} // eslint-disable-line @typescript-eslint/no-extraneous-class + // Note: Using new Function to prevent whitespace modifications in tsimp + const minifiedClass = new Function('return class{};'); // eslint-disable-line no-new-func + const classDeclarations = [ Foo, class Bar extends Foo {}, + minifiedClass(), ]; for (const classDeclaration of classDeclarations) {