【发布时间】:2018-07-27 05:30:24
【问题描述】:
我有以下返回 Promise 的异步函数。
static getAccessToken(env: DeploymentEnv, username: string, password: string): Promise<AccessToken>;
现在,这是我为它编写的单元测试。
it("should be able to get access token",async ()=>{
let accessToken = await IModelHubServiceBusClient.getAccessToken('QA',
'abc@xyz.com',
'abc')!;
assert.exists(accessToken);
});
运行时,测试失败,提示以下错误:
should be able to get access token:
Error: Timeout of 2000ms exceeded. For async tests and hooks, ensure "done()" is called; if returning a Promise, ensure it resolves.
我做错了什么,任何建议将不胜感激。 提前致谢。
【问题讨论】:
-
向我们展示
getAccessToken的实现,或确保它始终被解析/拒绝 -
static getAccessToken(env, username, password) { return __awaiter(this, void 0, void 0, function* () { const promise = new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () { let auth = yield new ImsClients_1.ImsActiveSecureTokenClient(env).getToken(username, password); let atoken = yield new ImsClients_1.ImsDelegationSecureTokenClient(env).getToken(auth); if (atoken) { resolve(atoken); } reject("Failed to get token"); })); return promise; }); }
标签: typescript asynchronous promise mocha.js chai