简体   繁体   English

Angular2单元测试环境设置? 如何触发鼠标事件?

[英]Angular2 unit test environment setup? How to do trigger mouse event?

Is it better to test angular2 code use Jasmine core or use protractor? 使用Jasmine核心还是使用量角器来测试angular2代码更好吗?

It seems so hard to test with mouse event in Jasmine, can anyone know how to do with it? 在Jasmine中使用鼠标事件进行测试似乎太难了,有人知道如何使用它吗? Can we do as simple as it likes in protractor: element1.click(). 我们可以像在量角器中一样简单吗:element1.click()。

This question is vague. 这个问题含糊不清。 Jasmine is a framework and can be used to execute tests against any stack, E2E, integration, unit. Jasmine是一个框架,可用于针对任何堆栈,端到端,集成,单元​​执行测试。 Protractor is an E2E testing framework that understands Angular directives and customizes WDJS control flow etc. They are not the same thing. Protractor是一个E2E测试框架,它了解Angular指令并自定义WDJS控制流等。它们不是同一回事。

If you want to test the side effects of a click, unit test the event. 如果要测试单击的副作用,请对事件进行单元测试。 The DOM reacts to the view model, so just test the state of the view model. DOM对视图模型做出反应,因此只需测试视图模型的状态即可。 This will be much faster.Protractor is useful when its unit tests wont fit, so you have to write a functional test. 这样会更快。当量角器的单元测试不合适时,它就很有用,因此您必须编写一个功能测试。 Always start with unit, and move out if it can't be tested that way 始终从单元开始,如果无法通过这种方式进行测试,则将其移出

See (outdated) docs 查看(过时的)文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM