on applying toBeA() method on expect().toBe() it gives an error that cann't read the property of undefined

对着背影说爱祢 提交于 2020-01-05 09:13:15

问题


I am applying toBeA() method on expect() and it gives the error TypeError: Cannot read property 'toBeA' of undefined how can I apply these methods by chaining.

utils.test.js code

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

it('should add two numbers',() => {
  var res = utils.add(44,11);
  expect(res).toBe(55).toBeA('number');  ----> here it gives the above error.

});
it('Object should be equal',() => {

  expect([1,2,5,7]).toInclude(5); ---> here it gives the error TypeError: expect(...).toInclude is not a function
});

utils.js code

module.exports.add = (a, b) => a + b ;

How do I fix this issue ?


回答1:


The expect package API has changed since Jest took ownership and they renamed some of the methods. If you check the code of the expect package you will find out the toBeA and toInclude methods are not available anymore.

You can change your implementation with these methods that are available in the v.23.4.0.

it('should add two numbers',() => {
  var res = utils.add(44,11);
  expect(typeof res).toBe('number');
  expect(res).toBe(55);
});

it('Object should be equal',() => {
  expect([1,2,5,7]).toContain(5);
});


来源:https://stackoverflow.com/questions/51574253/on-applying-tobea-method-on-expect-tobe-it-gives-an-error-that-cannt-read

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!