小编R.A*_*cas的帖子

让Mocha在运行下一个测试之前等待

有一些mocha测试需要先前函数调用的数据,但之后因为它使用了web服务,并且希望它在运行下一个测试之前确实等待预定的时间,例如:

var global;

it('should give some info', function(done) {
  run.someMethod(param, function(err, result) {
    global = result.global
  done();
  });
});

wait(30000); // basically block it from running the next assertion

it('should give more info', function(done) {
  run.anotherMethod(global, function(err, result) {
    expect(result).to.be.an('object');
  done();
  });
});
Run Code Online (Sandbox Code Playgroud)

任何想法,将不胜感激.谢谢!

javascript mocha.js node.js

14
推荐指数
4
解决办法
4万
查看次数

jsonwebtoken Typescript 编译问题?

我正在尝试编译一个打字稿文件,它不断从编译器中抛出这个错误: error TS2339: Property 'payload' does not exist on type 'string | object'. Property 'payload' does not exist on type 'string'.

有问题的代码:

decode(token: string): any {
  const decodedJWT = jwt.decode(token, { complete: true });

  const issuer = decodedJWT.payload.iss;
                           ^^^^^^^^^
  return {};
}
Run Code Online (Sandbox Code Playgroud)

我正在使用@types/jsonwebtoken库来定义类型。任何帮助将非常感激。

typescript json-web-token

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