-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat!: parameter object is null object (#333)
* feat: parameter object is null object * exclude windows and node 14
- Loading branch information
Showing
3 changed files
with
57 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict' | ||
|
||
const NullObject = function () {} | ||
NullObject.prototype = Object.create(null) | ||
|
||
module.exports = { | ||
NullObject | ||
} |
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 |
---|---|---|
@@ -0,0 +1,36 @@ | ||
'use strict' | ||
|
||
const { test } = require('tap') | ||
const { NullObject } = require('../lib/null-object') | ||
|
||
test('NullObject', t => { | ||
t.plan(2) | ||
const nullObject = new NullObject() | ||
t.ok(nullObject instanceof NullObject) | ||
t.ok(typeof nullObject === 'object') | ||
}) | ||
|
||
test('has no methods from generic Object class', t => { | ||
function getAllPropertyNames (obj) { | ||
var props = [] | ||
|
||
do { | ||
Object.getOwnPropertyNames(obj).forEach(function (prop) { | ||
if (props.indexOf(prop) === -1) { | ||
props.push(prop) | ||
} | ||
}) | ||
} while (obj = Object.getPrototypeOf(obj)) // eslint-disable-line | ||
|
||
return props | ||
} | ||
const propertyNames = getAllPropertyNames({}) | ||
t.plan(propertyNames.length + 1) | ||
|
||
const nullObject = new NullObject() | ||
|
||
for (const propertyName of propertyNames) { | ||
t.notOk(propertyName in nullObject, propertyName) | ||
} | ||
t.equal(getAllPropertyNames(nullObject).length, 0) | ||
}) |