angularjs – 使用Jasmine进行端到端测试
发布时间:2020-12-17 07:07:36 所属栏目:安全 来源:网络整理
导读:我正在尝试对使用AngularJS编写的应用程序执行一些端到端测试.目前,我在e2e.tests.js中设置了以下测试: describe('MyApp',function() { beforeEach(function() { browser().navigateTo('../index.html'); }); it('should be true',function() { expect(true
我正在尝试对使用AngularJS编写的应用程序执行一些端到端测试.目前,我在e2e.tests.js中设置了以下测试:
describe('MyApp',function() { beforeEach(function() { browser().navigateTo('../index.html'); }); it('should be true',function() { expect(true).toBe(true); }); }); 奇怪的是,这个基本测试失败了.测试本身就运行了.但结果是: 203ms browser navigate to '../index.html' 5ms expect undefined toBe true http://localhost:81/tests/e2e.tests.js:10:9 expected true but was undefined 考虑到“真实”是硬编码的,我希望它通过这个测试.我不知道未定义的真实性.我错过了什么? 解决方法
关于Angular的E2E测试框架的事情看起来像Jasmine,但它不是Jasmine. E2E测试代码实际上都是异步的,但它是以巧妙的方式编写的,因此调用看起来很正常.大多数调用创建异步任务和稍后测试的Future对象. Future对象有点像承诺,但它有点不同.它有一个value属性,它在准备就绪时设置,然后调用done函数移动到下一步.在E2E测试中,expect函数采用Future对象,而不是值.你看到未定义因为expect正在测试future.value,在这种情况下是true.value,这是未定义的.
尝试使用其中一个available selectors that return futures,然后测试结果.像这样的东西: expect(element("html").text()).toMatch("Our App"); Future对象没有很好地记录,但您应该能够像这样手动创建Future: var trueFuture = angular.scenario.Future( "a true value",// name that is displayed in the results function(callback) { // "behavior" function callback(null,true); // supposed to call callback with (error,result) }); expect(trueFuture).toEqual(true); 如果查看ng-scenario源代码,可以看到place where the matcher tests (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |