小编cna*_*nak的帖子

玩笑错误:TypeError:无法读取未定义的属性(读取“发送”)

我对玩笑测试相当陌生,并且认为我应该为我的一个控件编写一个简单的测试,该测试仅发送一组用户对象,或者如果该数组为空则发送一个简单的字符串语句。所以这个测试应该只传递文本“No users found”。

这是我写的简单测试:

test('Should return a string statment *No users found*', () => {
    expect(getAllUsers().toBe('No users found'));
});
Run Code Online (Sandbox Code Playgroud)

不知道我在这里做错了什么......

这是我收到的错误:

 TypeError: Cannot read properties of undefined (reading 'send')

       6 |
       7 | export const getAllUsers = (req, res) => {
    >  8 |     if(users.length === 0) res.send('No users found');
         |                                ^
       9 |     res.send(users);
      10 | };
      11 |
Run Code Online (Sandbox Code Playgroud)

node.js jestjs

16
推荐指数
1
解决办法
9万
查看次数

标签 统计

jestjs ×1

node.js ×1