2026/4/16 22:36:18
网站建设
项目流程
深圳网站建设制作开发,企业标准型手机网站,苍梧县网站建设,wordpress 默认模版测试 Express 服务器与保障代码安全 1. 使用 SuperTest 测试 Express 服务器 在测试 Express 服务器时,可能会遇到各种错误。例如: - html response returns your User Agent 测试中出现 TypeError: Cannot read property trim of null 。 - plain text response re…测试 Express 服务器与保障代码安全1. 使用 SuperTest 测试 Express 服务器在测试 Express 服务器时,可能会遇到各种错误。例如:-html response returns your User Agent测试中出现TypeError: Cannot read property 'trim' of null。-plain text response returns a plain text response测试中出现Error: expected "Content-Type" matching /text\/plain/, got "text/html; charset=utf-8"。-plain text response returns your User Agent测试中出现Error: Response does not contain User Agent。不过,这些错误比 “Cannot find module” 要好很多,说明确实在对实际的内容进行测试。接下来,我们要编写应用代码,让这些测试从失败(红色)变为通过(绿色)。1.1 编写首个测试的代码在项目根目录的app.js中添加以下代码:var express = require("expr