Skip to content
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

[v5] assert.isFunction() fails with async function #1564

Closed
ReDemoNBR opened this issue Dec 28, 2023 · 4 comments · Fixed by #1566
Closed

[v5] assert.isFunction() fails with async function #1564

ReDemoNBR opened this issue Dec 28, 2023 · 4 comments · Fixed by #1566

Comments

@ReDemoNBR
Copy link
Contributor

ReDemoNBR commented Dec 28, 2023

The function assert.isFunction is failing on AsyncFunction on v5.0.0, while on v4.3.10 it was working

A simple scenario is the one below:

describe("Scenario", ()=>{
    it("Should be a function", ()=>{
        async function foo() {
            console.log("Hello World");
        }
        assert.isFunction(foo); // fails on v5.0.0
    });
});

For now I changed my tests to use the JS builtin typeof, like:

assert.strictEqual(typeof foo, "function");`
@koddsson
Copy link
Member

Wow! Weird that we haven't hit this before. I don't even see a test for this so it makes sense we didn't catch this in the upgrade. I've created a failing test on a local branch and I'll see if I can make a fix today. I'll keep you posted.

@43081j
Copy link
Contributor

43081j commented Dec 29, 2023

@koddsson its most likely because an async function's tag is AsyncFunction, not Function

presumably the library we used to use just treated them as one

edit:

here you go:
https://github.com/chaijs/type-detect/blob/4415ced2c49007f097627515806553e7f649c293/index.ts#L69-L72

@koddsson koddsson mentioned this issue Dec 29, 2023
@koddsson
Copy link
Member

@koddsson its most likely because an async function's tag is AsyncFunction, not Function

presumably the library we used to use just treated them as one

Yup! We refactored type-detect as part of v5. Now the question is if this functionality is actually correct and we should introduce isAsyncFunction to be more granular in assertions.

I put together a draft PR here and wrote down some thoughts: #1566

@asamuzaK
Copy link

asamuzaK commented Jan 6, 2024

There is a similar issue with assert.typeOf(async ()=> {}, 'function').

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants