-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
63 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,67 +1,73 @@ | ||
import assert from 'node:assert/strict' | ||
import test from 'node:test' | ||
import {hasProperty} from './index.js' | ||
import * as mod from './index.js' | ||
|
||
test('hasProperty', () => { | ||
assert.deepEqual( | ||
Object.keys(mod).sort(), | ||
['hasProperty'], | ||
'should expose the public api' | ||
) | ||
test('hasProperty', async function (t) { | ||
await t.test('should expose the public api', async function () { | ||
assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ | ||
'hasProperty' | ||
]) | ||
}) | ||
|
||
assert.equal( | ||
hasProperty(null, 'alpha'), | ||
false, | ||
'should return `false` without node' | ||
) | ||
await t.test('should return `false` without node', async function () { | ||
assert.equal(hasProperty(null, 'alpha'), false) | ||
}) | ||
|
||
assert.equal( | ||
hasProperty({type: 'text', value: 'alpha'}, 'bravo'), | ||
false, | ||
'should return `false` without `element`' | ||
) | ||
await t.test('should return `false` without `element`', async function () { | ||
assert.equal(hasProperty({type: 'text', value: 'alpha'}, 'bravo'), false) | ||
}) | ||
|
||
assert.equal( | ||
hasProperty({type: 'element'}, 'charlie'), | ||
false, | ||
'should return `false` without properties' | ||
) | ||
await t.test('should return `false` without properties', async function () { | ||
assert.equal(hasProperty({type: 'element'}, 'charlie'), false) | ||
}) | ||
|
||
assert.equal( | ||
hasProperty({type: 'element', properties: {}}, 'toString'), | ||
false, | ||
'should return `false` for prototypal properties' | ||
await t.test( | ||
'should return `false` for prototypal properties', | ||
async function () { | ||
assert.equal( | ||
hasProperty({type: 'element', properties: {}}, 'toString'), | ||
false | ||
) | ||
} | ||
) | ||
|
||
assert.equal( | ||
hasProperty( | ||
{ | ||
type: 'element', | ||
properties: {id: 'delta'} | ||
}, | ||
'echo' | ||
), | ||
false, | ||
'should return `false` if the property does not exist' | ||
await t.test( | ||
'should return `false` if the property does not exist', | ||
async function () { | ||
assert.equal( | ||
hasProperty( | ||
{ | ||
type: 'element', | ||
properties: {id: 'delta'} | ||
}, | ||
'echo' | ||
), | ||
false | ||
) | ||
} | ||
) | ||
|
||
assert.equal( | ||
// @ts-expect-error runtime. | ||
hasProperty({type: 'element', properties: {id: 'delta'}}), | ||
false, | ||
'should return `false` if without `name`' | ||
) | ||
await t.test('should return `false` if without `name`', async function () { | ||
assert.equal( | ||
// @ts-expect-error: check how a missing name is handled. | ||
hasProperty({type: 'element', properties: {id: 'delta'}}), | ||
false | ||
) | ||
}) | ||
|
||
assert.equal( | ||
hasProperty( | ||
{ | ||
type: 'element', | ||
properties: {id: 'delta'} | ||
}, | ||
'id' | ||
), | ||
true, | ||
'should return `true` if the property does exist' | ||
await t.test( | ||
'should return `true` if the property does exist', | ||
async function () { | ||
assert.equal( | ||
hasProperty( | ||
{ | ||
type: 'element', | ||
properties: {id: 'delta'} | ||
}, | ||
'id' | ||
), | ||
true | ||
) | ||
} | ||
) | ||
}) |