小编Dan*_*iel的帖子

Nestjs 单元测试 - 模拟方法保护

我已经开始使用 NestJS 并且有一个关于模拟单元测试的守卫的问题。我正在尝试测试一个基本的 HTTP controller,它有一个方法 Guard 附加到它。

当我向 Guard 注入服务时,我的问题就开始了(我需要ConfigServiceGuard 的服务)。

运行测试时,DI 无法解析 Guard

  ? AppController › root › should return "Hello World!"

    Nest can't resolve dependencies of the ForceFailGuard (?). Please make sure that the argument at index [0] is available in the _RootTestModule context.
Run Code Online (Sandbox Code Playgroud)

我的力量失败守卫:

  ? AppController › root › should return "Hello World!"

    Nest can't resolve dependencies of the ForceFailGuard (?). Please make sure that the argument at index [0] is available in the …
Run Code Online (Sandbox Code Playgroud)

unit-testing dependency-injection mocking jestjs nestjs

9
推荐指数
2
解决办法
4952
查看次数

将套接字客户端与 NestJs 微服务结合使用

我最近开始使用 NestJs 并在尝试使用TCP 客户端测试我的NestJs 微服务应用程序时获得了库存

是否可以触发@EventPattern@MessagePattern()使用非嵌套应用程序?

尝试此方法时,套接字客户端只是停留在trying to connect.

有任何想法吗?

谢谢。

javascript sockets node.js microservices nestjs

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

Go 错误返回模式的名称是什么?

Go 不支持 try-catch,相反,Go 错误处理的编码风格是在潜在的有效值旁边返回错误。如果错误符合,则错误将被设置为error接口的实现,否则将被设置为nil

请参阅流动的签名:

func Open(name string) (file *File, err error)
Run Code Online (Sandbox Code Playgroud)

我想知道这个“错误处理”模式的名称是什么。

go

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

茉莉花不加载帮助文件

我正在尝试运行茉莉花助手脚本,但它们没有被拾取。我正在研究jasmine API,它看起来很简单,只需添加helpersjasmine.json.

这是我正在测试的助手之一。它的唯一目的是在调用 jasmine 时创建一个文件。

助手/fileHelper.js

var fs = require('fs');

fs.writeFile("./jasmineHelperOutput.txt", "Hey there!", function(err) {

    if(err) {
        return console.log(err);
    }

}); 
Run Code Online (Sandbox Code Playgroud)

茉莉花.json

{
    "spec_dir": "./spec",
    "spec_files": [
        "**/*.spec.js"
    ],
    "helpers": [
        "helpers/**/*.js"
    ]
}
Run Code Online (Sandbox Code Playgroud)

设置:

  • 操作系统:win10
  • 节点:8.1.3
  • npm:5.0.3

但这不起作用。

我缺少什么?

我在https://github.com/dannyhuly/jasmine-with-helpers创建了一个简单的 jasmine 项目来解决当前的问题。

谢谢。

node.js jasmine

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