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

toBeInstanceOf( Function ) not working as expected. #5946

Closed
trusktr opened this issue Apr 9, 2018 · 9 comments
Closed

toBeInstanceOf( Function ) not working as expected. #5946

trusktr opened this issue Apr 9, 2018 · 9 comments

Comments

@trusktr
Copy link

trusktr commented Apr 9, 2018

Jest 22.4.3

I've got this test, that works:

    expect( typeof bar.method ).toBe( 'function' ) // it works

but then this fails:

    expect( bar.method ).toBeInstanceOf( Function )

with output:

    expect(value).toBeInstanceOf(constructor)

    Expected value to be an instance of:
      "Function"
    Received:
      [Function method]
    Constructor:
      "Function"

      270 |     console.log('1')
      271 |     expect( typeof bar.method ).toBe( 'function' )
    > 272 |     expect( bar.method ).toBeInstanceOf( Function )
      273 |
      274 |     Bar = Class({
      275 |         method() {}

Seems like it should not fail.

@trusktr
Copy link
Author

trusktr commented Apr 9, 2018

I can make a repro if needed, but first let me know if I'm expecting something I shouldn't be expecting (no pun intended! 😊 ).

@SimenB
Copy link
Member

SimenB commented Apr 9, 2018

How is method created?

@trusktr
Copy link
Author

trusktr commented Apr 10, 2018

comment deleted (I made a mistake in this comment, but not in the original post)

@trusktr
Copy link
Author

trusktr commented Apr 10, 2018

@SimenB method is created something like this:

let o = {
  method() { ... }
}

then eventually

expect( o.method ).toBeInstanceOf( Function )

@trusktr
Copy link
Author

trusktr commented Apr 10, 2018

Okay, nevermind, I didn't make a mistake in my second comment.

I've got code like this that I can make my test pass with:

    // strange!
    expect( typeof result ).toBe( 'object' )
    expect( result ).not.toBeInstanceOf( Object )
    expect( result.constructor.name ).toBe( 'Object' )
    expect( result.constructor ).not.toBe( Object )

result is a simple object literal that is returned from a function that I've imported from another file.

@SimenB
Copy link
Member

SimenB commented Apr 10, 2018

Might be #2549?

@trusktr
Copy link
Author

trusktr commented Apr 11, 2018

Yep, seems like it might be the same thing.

@SimenB
Copy link
Member

SimenB commented Apr 11, 2018

Closing as dupe, then. Follow that for updates (hope to have it solved for jest 23)

@SimenB SimenB closed this as completed Apr 11, 2018
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants