Jest: Bug: toBeA() not functioning as expected

Created on 16 Oct 2017  路  6Comments  路  Source: facebook/jest


Do you want to request a feature or report a bug?
Report a bug (on expect, which was acquired by jest since v21+)

What is the current behavior?
screenshot from 2017-10-06 13-54-09

expect(5).toBeA('number');

is giving error: TypeError: expect(...).toBeA is not a function

If the current behavior is a bug, please provide the steps to reproduce and either a repl.it demo through https://repl.it/languages/jest or a minimal repository on GitHub that we can yarn install and yarn test.
Trivial, from the screenshot attached above. However, I've still made a minimal repository with the exact same configurations: https://github.com/thesemicolonguy/node-test

What is the expected behavior?
It should work according to documentation here

Please provide your exact Jest configuration and mention your Jest, node, yarn/npm version and operating system.
node v6.11.2
expect v21.2.1

I'd created an issue on the expect repository here. It was closed and I was asked to make a new issue on this repository.

Most helpful comment

This matcher is not supported. Use expect(typeof number).toBe('number').

All 6 comments

This matcher is not supported. Use expect(typeof number).toBe('number').

Thanks @cpojer. Issue solved.

Can we make toBeOfType as one of the default matchers on jest?

I don't think it's necessary. You can use https://github.com/jest-community/jest-extended#tobenumber if you want

IMO, as a newbie to JavaScript & Jest, It's easier if the type checking matcher is provided out of the box, specially considering typeof doesn't give me right results for everything.

Was this page helpful?
0 / 5 - 0 ratings