小编Kri*_*hna的帖子

使用 JEST 模拟 Express 连锁响应

我对笑话和打字稿很陌生,我正在尝试为笑话中的控制器功能创建一个小型单元测试

import { Request, Response } from 'express';

const healthCheck = (_req: Request, _res: Response) => {
  const value = _req.params.name ?? 'World!';
  return _res.status(200).json({ message: `Hello ${value}` });
};

export default healthCheck;
Run Code Online (Sandbox Code Playgroud)

我为上述函数编写的单元测试是

import { Request, Response } from 'express';

import healthCheck from './health.controller';

describe('Health Controller', () => {
  it('healthCheck should send 200 on an optional path param', () => {
    const req = { params: {} } as Request;
    const res = {
      json: jest.fn(),
      status: jest.fn(),
    } …
Run Code Online (Sandbox Code Playgroud)

node.js express typescript jestjs

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

如何一次性取消所有环境变量?

我正在尝试在拆卸块中的代码中取消设置环境变量。有没有一个命令可以一次性取消所有变量?

例如 我正在设置以下环境变量

export username=test
export password=password
export table=employees
Run Code Online (Sandbox Code Playgroud)

我正在使用unset命令来取消设置变量

unset username
unset password
unset table
Run Code Online (Sandbox Code Playgroud)

是否有一个命令可以立即取消所有设置,例如unset all

linux shell powershell environment-variables node.js

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