对于使用expect..的循环纯函数jest测试..无法读取属性



我正在尝试使用for循环制作一个纯函数,在终端中通过一个jest test/npm测试。。。我得到一个错误,它无法读取toBe的属性。。。

我的功能:

const syntax = {
for1: (a,b) => {
for(let a=1; a<10; a++){
for(let b=1; b<10; b++){
return a+b;
}
}
}
}

我的Test.js文件:我想让它测试1+2不等于0,使这个测试通过函数

test('FORLOOP', () => {
expect(syntax.for1(1,2).not.toBe(0));
});

终端类型错误:

TypeError: Cannot read property 'toBe' of undefined
45 | test('FORLOOP', () => {
> 46 |     expect(syntax.for1(1+3).not.toBe(0));
|            ^
47 | });

更改:

测试文件:(固定括号(

test('FORLOOP', () => {
expect(syntax.for1(1,2).not.toBe(0));
});
TypeError: _syntax.default.for1 is not a function
55 | 
56 | test('FORLOOP', () => {
> 57 |     expect(syntax.for1(1+3)).not.toBe(0);
|                   ^
58 | });

括号放错地方了。应该是:

expect(syntax.for1(1+3)).not.toBe(0);

不是

expect(syntax.for1(1+3).not.toBe(0));

CCD_ 1需要根据CCD_ 2的结果而不是根据syntax.for1(1+3)的结果来调用。

最新更新