我在expect()上应用toBeA()方法,它给出了错误TypeError:无法读取未定义的属性'toBeA'我如何通过链接应用这些方法。
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 ;
如何解决这个问题?
最佳答案
自 Jest 以来,expect
包 API 已发生更改他们取得了所有权并重新命名了一些方法。
如果您检查code在 expect
包中,您会发现 toBeA
和 toInclude
方法不再可用。
您可以使用 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);
});
关于node.js - 在expect().toBe()上应用toBeA()方法时,它会给出一个错误,无法读取未定义的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51574253/