Unit testing a method that creates a JWT and returns Error: secretOrPrivateKey must have a value
Unit testing a method that creates a JWT and returns Error: secretOrPrivateKey must have a value
我正在尝试为我编写的生成 JWT 的方法编写单元测试。我正在做以下事情
describe('returns a token', function() {
it('should return a token', function() {
let req = {};
const a = authenticatorClass.returnToken(req);
console.log(a);
});
注意:我还没有使用 expect,首先通过将方法的结果记录到控制台来查看该方法是否有效
我收到以下错误:Error: secretOrPrivateKey must have a value
这是我要测试的方法:
returnToken(expressRequestObject) {
const payload = {};
return jwt.sign(
payload,
SECRET,
{ expiresIn: '30d' },
);
}
我在这里做错了什么? TIA
可能是你的SECRET
没有任何价值,你能记录下来吗?
我正在尝试为我编写的生成 JWT 的方法编写单元测试。我正在做以下事情
describe('returns a token', function() {
it('should return a token', function() {
let req = {};
const a = authenticatorClass.returnToken(req);
console.log(a);
});
注意:我还没有使用 expect,首先通过将方法的结果记录到控制台来查看该方法是否有效
我收到以下错误:Error: secretOrPrivateKey must have a value
这是我要测试的方法:
returnToken(expressRequestObject) {
const payload = {};
return jwt.sign(
payload,
SECRET,
{ expiresIn: '30d' },
);
}
我在这里做错了什么? TIA
可能是你的SECRET
没有任何价值,你能记录下来吗?