问题
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