【发布时间】:2021-02-19 05:00:58
【问题描述】:
我正在使用 Jasmine 来尝试和测试具有以下模式的代码:
(这本质上是一个分页的数据库表加载)
1. controller calls api on load
2. api.then updates $scope variable
3. controller $watch-es that $scope variable
a. If new value meets criteria, call api again
b. api.then updates $scope variable
c. controller $watch-es the change
i. eventually new value does not meet criteria and call chain is stopped
现在我的单元测试有 2 个延迟承诺。一个返回一个通过 $watch 检查的值,一个执行相反的操作。但是,第二个承诺的 then() 没有被调用。努力了解我需要在哪里解决承诺和$digest
查看一个简化的 plunker:https://plnkr.co/edit/543Q5vGJqTYzkSvh
我希望 $scope.$watch 方法在第二次 api 调用之后记录一些内容。
我的单元测试中缺少什么
【问题讨论】:
标签: javascript angularjs unit-testing jasmine