测试驱动开发的起步与实践
1. 测试驱动开发的初步尝试
在进行测试驱动开发时,我们首先运行测试,结果测试失败。在输出中会看到如下代码:
ReferenceError: Appointment is not defined
5 | it("renders the customer first name", () => {
6 | const customer = { firstName: "Ashley" };
> 7 | const component = (
8 | <Appointment customer={customer} />
| ^
9 | );
这是一个运行时异常,而非期望失败。它明确告诉我们需要构建 Appointment 组件。
接下来,我们要让失败的测试通过,具体操作步骤如下:
1. 在 test/Appointment.test.js 文件中,在两个 React 导入语句下方添加新的导入语句:
import { Appointment } from "../src/Appointment";
- 运行
npm test命令,此时会得到一个不同的错误,关键信息如下:
Cannot find
超级会员免费看
订阅专栏 解锁全文
1226

被折叠的 条评论
为什么被折叠?



