在对Expect().toBe()应用toBeA()方法时,它给出了无法读取undefined属性的错误 [英] on applying toBeA() method on expect().toBe() it gives an error that cann't read the property of undefined

查看:185
本文介绍了在对Expect().toBe()应用toBeA()方法时,它给出了无法读取undefined属性的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Expect()上应用了toBeA()方法,它给出了错误 TypeError:无法读取未定义的属性"toBeA" .如何通过链接应用这些方法.

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代码

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代码

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

如何解决此问题?

推荐答案

开玩笑获得所有权,他们重命名了某些方法. 如果您查看expect包,您将发现toBeAtoInclude方法不再可用.

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.

您可以使用23.4.0版中可用的这些方法来更改实现.

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);
});

这篇关于在对Expect().toBe()应用toBeA()方法时,它给出了无法读取undefined属性的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆