简体   繁体   English

如何在ember.js中执行单元测试?

[英]How can I perform unit test in ember.js ?

I've been developing a web application where I'm using ember.js 1.0. 我一直在开发一个使用ember.js 1.0的Web应用程序。 I was wondering if there is any way or framework to make unit test in ember. 我想知道是否有任何方法或框架可以在ember中进行单元测试。

For instance, suppose that I've a controller called "CustomerController" and I have a method to add need items to a shopping cart. 例如,假设我有一个名为“ CustomerController”的控制器,并且我有一种将需要的物品添加到购物车的方法。

...
addNewItem : function(item){
    var content = shoppingCart.get("content");
    content.push(item);
    shoppingCart.set("content", content);
}
...

So i want to perform a unit test to see if the number of items increase when the customer add a new item. 因此,我想执行单元测试以查看客户添加新项目时项目数是否增加。 What kind of framework I can used to accomplish this? 我可以使用哪种框架来完成此任务?

Qunit works well with ember and has great async support. Qunit与ember配合良好,并具有强大的异步支持。 It's used to test ember itself. 它用于测试余烬本身。

Check out ember-app-kit , which uses qunit and the karma test runner. 查看ember-app-kit ,它使用qunit和karma测试运行程序。 It includes a couple example tests, as well as some intro articles referenced in the "Getting Started" section of the README. 它包括几个示例测试,以及自述文件的“入门”部分中引用的一些介绍性文章。

Best way for this is using Jasmine 最好的方法是使用茉莉花

There is a blog post explaining your answer completely here: 这里有一篇博客文章,全面解释了您的答案:

Unit Testing Ember.js, How I Learned to Stop Worrying and Love the Runloop 单元测试Ember.js,我如何学会停止担心和热爱Runloop

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

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