【发布时间】:2022-01-06 19:29:00
【问题描述】:
在Login 函数组件中,我有一个函数validateForm,它检查username 和password 的长度是否大于零。
function validateForm() {
return username.length > 0 && password.length > 0;
}
我使用 Jest 作为单元测试工具。
import React from "react";
import Login, { validateForm } from "./Login";
import { render, screen } from "@testing-library/react";
describe("LoginUser", () => {
test("validate username and password should be greater than 0", () => {
var username = "name";
var password = "pass";
expect(validateForm(username.length)).toBeGreaterThan(0);
});
});
TypeError: (0 , _Login.validateForm) is not a function
我在运行测试用例时遇到了上述错误。如何解决这个错误?
【问题讨论】:
标签: reactjs react-hooks jestjs ts-jest