小编Ana*_*dac的帖子

笑话和酶| 收到的值必须是一个函数,收到的未定义

我有一个小功能,用于检查用户名是否唯一。见下文:

export const validateUsername = value =>
  listUsers({ once: true }).then(({ data }) => {
    if (Array.isArray(data) && data.find(userData => userData.username === value)) {
      // eslint-disable-next-line no-throw-literal
      throw 'Username already exists';
    }
  });
Run Code Online (Sandbox Code Playgroud)

我想为它写一些测试。但我收到这个错误

Received value must be a function, but instead "undefined" was found
Run Code Online (Sandbox Code Playgroud)

你能向我解释什么是错的。我的意思是,这是一个异步函数,当时它是未定义的,但不确定它想让我做什么。

  it('Accept the data if the passed userName is unique', async () => {
    expect(await validateUsername('Username is unique')).not.toThrow();
  });
Run Code Online (Sandbox Code Playgroud)

unit-testing async-await reactjs jestjs enzyme

1
推荐指数
1
解决办法
3088
查看次数

标签 统计

async-await ×1

enzyme ×1

jestjs ×1

reactjs ×1

unit-testing ×1