syntax-tree / unist-util-is

utility to check if a node passes a test
https://unifiedjs.com
MIT License
38 stars 8 forks source link

Improve documentation on is() and is.convert()() not beein equivalent #12

Closed Roang-zero1 closed 4 years ago

Roang-zero1 commented 5 years ago

is and is.convert()() do not have the same behavior.

The function created through convert() do not have the same results as calling is() directly, even when using the same tests.

I've rewritten all tests from is() to convert()() at Roang-zero1/unist-util-is/tree/convert-test. Running these tests failes 14 tests (e.g. for invalid index).

Steps to reproduce

git clone https://github.com/Roang-zero1/unist-util-is.git
npm install
npm run test

Expected behaviour

From my understanding is() and convert()() should be equivalent.

Actual behaviour

is(node, null, -1) throws and error while

const testNull = convert(null)
testNull(node, -1)

returns undefined.

wooorm commented 5 years ago

Hmm, I don’t think they should be the same, otherwise, why use convert? Convert is faster on valid input, precisely because it doesn’t test for invalid input, and that’s its use case

wooorm commented 5 years ago

Could be clearer in the docs!

ChristianMurphy commented 4 years ago

resolved in #13