我已经开始使用 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) Laravel 路由中有一个后备方法:
Route::fallback(function () {
//
});
Run Code Online (Sandbox Code Playgroud)
正常的路线是这样的:
Route::get('/user', 'UserController@list');
Run Code Online (Sandbox Code Playgroud)
有一种方法可以像这样使用后备路由:
Route::fallback('FallbackController@index');
Run Code Online (Sandbox Code Playgroud)