mjackson / expect

Write better assertions
MIT License
2.29k stars 117 forks source link

toBeA() returns an error saying it is not a function or cannot read property of #240

Closed davidshare closed 6 years ago

davidshare commented 6 years ago

I'm trying to check if the result of a function is a number, and it keeps returning an error that it cannot read property toBeOf undefined. Here is the code

it('should square a numbers', ()=>{ let res = utils.square(5); expect(res).toBe(25).toBeA('number'); });

image

ljharb commented 6 years ago

Which version of expect are you using? v21+ is managed by jest.

MatthewKosloski commented 6 years ago

I get same error with expect 22.0.6.

Copied the code straight from the README.md

describe('Unit Test', () => {
    it('should not fail...?', () => {
        expect(2).toBeA('number');
    });
});
MatthewKosloski commented 6 years ago

Nevermind! Referenced from here

Test passed with:

expect(typeof 2).toBe('number');
ljharb commented 6 years ago

@MatthewKosloski expect v21+ is managed by the jest team; that includes v22.