【发布时间】:2020-05-26 04:02:10
【问题描述】:
以下代码未通过单元测试,因为 this.result 仍未定义。我的问题是变量范围、异步行为还是我没有想到的其他问题?我的最终目标是通过this.result == "somevalue"
describe("This is a test", ()=> {
beforeEach(async ()=> {
this.result = await "somevalue";
})
it("should be somevalue", async ()=> {
await this.result;
expect(this.result).toBe("somevalue")
})
});
编辑:我尝试了以下方法并让它工作,但是有没有办法传递这个。[一些变量]正如我们在 Jasmine 文档中看到的使用beforeEach()?
describe("This is a test", ()=> {
let result = undefined;
beforeEach(async ()=> {
result = await "somevalue";
});
it("should be somevalue", async ()=> {
await result;
expect(result).toBe("somevalue");
})
});
【问题讨论】:
-
你的单元测试中
this的上下文是什么?组件?
标签: typescript promise async-await jasmine jasmine-node