例如,我有以下文件:
规格/配置/文件mock.js
var mock = require('mock-fs');
mock({
'files': {
'expense.csv': 'a;b;c;d\n1;2;3;4\n5;6;7;8'
}
});
Run Code Online (Sandbox Code Playgroud)
应用/阅读/ reader.js
var fs = require('fs');
var reader = {
read: function(path) {
return fs.readFileSync(path, 'utf8');
},
write: function(path, object) {
fs.writeFileSync(path, object);
}
};
module.exports = reader;
Run Code Online (Sandbox Code Playgroud)
应用/阅读/ reader.spec.js
describe('reader.js test', function(){
var reader = require('./reader.js');
var mock = require('mock-fs');
it('should return a simple string', function(){
expect(reader.read('files/expense.csv')).toEqual('a;b;c;d\n1;2;3;4\n5;6;7;8');
});
it('should write a json object', function(){
// WHAT TO DO?!
});
});
Run Code Online (Sandbox Code Playgroud)
该reader.read函数与mock-fs工作正常.
但我正在尝试测试该 …
我已经安装了几个包在我的本地机器,但我无法知道我已经安装了哪些。
有一些框架,告诉我哪些软件包和版本安装在我的项目(未保存的,保存和开发保存)?
我试图比较node_modules文件夹,但结果不是很精确。
目前,我已经设法将 AuthGuard 与 JWT 身份验证结合使用,但我无法user在Roles.
我试图按照猫的例子,但我从来没有user定义过对象,你可以在第 14 行看到。
这是我的代码:
// auth.controller.ts
@Controller('auth')
@UseGuards(RolesGuard)
export class AuthController {
constructor(private readonly authService: AuthService) {}
@Get('token')
async createToken(): Promise<any> {
return await this.authService.createToken();
}
@Post()
@UseGuards(AuthGuard())
@Roles('admin')
findAll() {
// this route is restricted by AuthGuard
// JWT strategy
return 'Super important info';
}
}
// auth.module.ts
@Module({
imports: [
SharedModule,
PassportModule.register({ defaultStrategy: 'jwt' }),
JwtModule.registerAsync({
imports: [SharedModule],
useFactory: async (configService: ConfigService) => ({
secretOrPrivateKey: …Run Code Online (Sandbox Code Playgroud)