茉莉花角单位测试等待间谍组件有望解决
我们对一个 Angular 组件进行单元测试,该组件的目的是选择和上传文件。 在组件中我们将文件转换为base64字符串(后端要求) 并做一些其他检查。
仅当文件转换为 Base64 后,模板才会更新并显示 待上传附件。
这就是我们想要进行单元测试的内容:要上传的 Base64 编码文件列表的可见性。
以下是我们的 MWE 的链接(为了简洁起见,我们删除了与我们的问题无关的特定逻辑): https://stackblitz.com/edit/angular-jasmine-promise-await-bjvxuc?file=src%2Fapp%2Fapp.component.html
有没有办法让 jasmine 等待我们的 Angular 组件返回已解决的承诺,以便我们确定性地知道模板将重新渲染,以便我们可以预期附件列表已渲染?
We unit-test an Angular component that has the purpose to select and upload files.
In the component we convert files to base64 strings (backend requirement)
and do some other checks.
Only after the files have been converted to base64, the template updates and shows
to-be uploaded attachments.
This is what we want to unit-test: the visibility of a list of base64 encoded files to be uploaded.
Here is a link to our MWE (for brevity we removed specific logic that is not relevant to our question): https://stackblitz.com/edit/angular-jasmine-promise-await-bjvxuc?file=src%2Fapp%2Fapp.component.html
Is there a way to make jasmine wait for our Angular components returned promise to have resolved, such that we deterministically know that the template will have re-rendered, so that we can expect the attachment list to have been rendered?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在寻找的是
Angular
解决方案,很可能不是jasmine
解决方案。在 Angular 中有多种等待 Promise 的方法:
1.)
async
和await Fixture.whenStable()
2.)
waitForAsync
和fixture.whenStable()
waitForAsync
辅助方法在完成测试之前等待创建的 Promise 得到解析3.)
fakeAsync
和tick()
https://www. digitalocean.com/community/tutorials/angular-testing-async-fakeasync
以上是一篇好文章。您可以继续学习
fakeAsync
和tick
、fixture.whenStable()
和waitForAsync
。====编辑=====
What you're looking for are
Angular
solutions and most likely notjasmine
solutions.There are many ways to wait for promises in Angular:
1.)
async
andawait fixture.whenStable()
2.)
waitForAsync
andfixture.whenStable()
waitForAsync
helper method waits for promises created to be resolved before completing the test3.)
fakeAsync
andtick()
https://www.digitalocean.com/community/tutorials/angular-testing-async-fakeasync
The above is a good article. You can continue learning about
fakeAsync
andtick
,fixture.whenStable()
andwaitForAsync
.==== Edit =====