on applying toBeA() method on expect().toBe() it g

2019-07-22 09:32发布

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 ?

标签: node.js mocha
1条回答
贪生不怕死
2楼-- · 2019-07-22 10:08

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);
});
查看更多
登录 后发表回答