sindresorhus / ow

Function argument validation for humans
https://sindresorhus.com/ow/
MIT License
3.8k stars 105 forks source link

Fix `ow.object` to return `ArgumentError` when `null` or `undefined` is passed #211

Closed wafuwafu13 closed 3 years ago

wafuwafu13 commented 3 years ago

Fix: https://github.com/sindresorhus/ow/issues/201

sindresorhus commented 3 years ago

Can you rebase from the main branch and ensure the tests passes?

wafuwafu13 commented 3 years ago

object.ts › object.hasKeys is also failed 🤔

https://github.com/sindresorhus/ow/pull/211/checks?check_run_id=2734089247

result ```zsh object.ts › object.instanceOf /home/runner/work/ow/ow/test/object.ts:164 163: 164: t.throws(() => { 165: ow(null, ow.object.instanceOf(Unicorn)); Function threw unexpected exception: ArgumentError { validationErrors: Map { 'object' => Set { 'Expected argument to be of type `object` but received type `null`', 'Expected object `null` to be of type `Unicorn`', }, }, message: `Expected argument to be of type `object` but received type `null`␊ Expected object `null` to be of type `Unicorn``, } Expected message to equal: 'Expected object `null` to be of type `Unicorn`' Object.ow [as default] (source/index.ts:3:107) test/object.ts:165:5 test/object.ts:164:4 object.ts › object.hasKeys /home/runner/work/ow/ow/test/object.ts:190 189: 190: t.throws(() => { 191: ow({unicorn: '🦄'}, ow.object.hasKeys('unicorn', 'rainbow')); Function threw unexpected exception: ArgumentError { validationErrors: Map { 'object' => Set { 'Expected object to have keys `["rainbow"]`', }, }, message: 'Expected object to have keys `["rainbow"]`', } Expected message to equal: 'Expected object `Unicorn` to have keys `["rainbow"]`' Object.ow [as default] (source/index.ts:3:107) test/object.ts:191:5 test/object.ts:190:4 ```
wafuwafu13 commented 3 years ago

Fixed and tests passes :) https://github.com/sindresorhus/ow/pull/211/commits/becbd56b4d8ceeee9117631af5d55bc2bbc1e4fb