-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AsyncFunction and GeneratorFunction issues #103
Comments
Hey @doasync thanks for the issue This, again, is because of the early Lines 54 to 57 in c7895e4
We could probably change that to: var typeofObj = typeof obj;
if (typeofObj !== 'object' && typeofObj !== 'function') {
return typeofObj;
} We'd welcome a PR, which includes that change plus you'll need to change the tests for generatorfunction, which are here: type-detect/test/new-ecmascript-types.js Lines 129 to 135 in c7895e4
Also, on top of that, this lib does not have tests for async functions as they weren't around when the lib was written - so you'll need to add tests for that. |
Related issues: chaijs/chai#958 and chaijs/chai#949. I don't think there are enough good use cases for differentiating async/generator functions from regular ones: any function can return promise or iterator. If we change this, we will break pretty common If you really wish to detect async/generator functions, you can use ;(function* () {})[Symbol.toStringTag].should.equal("GeneratorFunction")
;(async function() {})[Symbol.toStringTag].should.equal("AsyncFunction") |
We could easily add a bit of extra code to chai to prevent breaking changes for the isFunction = expectedType === 'function' && typeof thing === 'function'
if (isFunction) {
assert(true)
} else {
assert(type(thing) === expected)
}
Granted, this adds more complexity in chai; but I am somewhat compelled by the following points:
At any rate, there's more discussion needed here. I'll remove the pr wanted tag and let's get other @chaijs/type-detect members to weigh in. |
I don't think there's a clear right or wrong answer here. I lean slightly toward the idea that it's reasonable for |
I would argue that |
I think, tests should pass:
Is it a bug? If not, you should add it to README.
The text was updated successfully, but these errors were encountered: