mjackson / expect

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

toBeA() function, throwing an 'undefined' error #237

Closed eazylaykzy closed 6 years ago

eazylaykzy commented 6 years ago

I've been trying to figure out what went wrong with my code for the past few hours, but i think the toBeA() is giving this the below error message:

1) should add two number: TypeError: Cannot read property 'toBeA' of undefined at Context.it (utils\utils.test.js:7:23)

Below is the actual code:

const expect = require('expect');
const utils = require('./utils');

it('should return the square of the number', () => {
  let res = utils.square(5);

  expect(res).toBe(25).toBeA('number');
});
ljharb commented 6 years ago

What version of expect are you using? v21+ is now managed by jest

eazylaykzy commented 6 years ago

Yes @ljharb , I'm using v21+ After going through the Readme Notice Github page, I found out the package has been donated to Facebook Jest, so i did a little search query on it, and fixed it with the code below:

it('should return the square of the number', () => {
  let res = utils.square(5);

  expect(res).toBe(25);
  expect(typeof res).toBe('number');
});

Thanks @ljharb