简体   繁体   中英

How can I perform unit test in ember.js ?

I've been developing a web application where I'm using ember.js 1.0. I was wondering if there is any way or framework to make unit test in ember.

For instance, suppose that I've a controller called "CustomerController" and I have a method to add need items to a shopping cart.

...
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. It's used to test ember itself.

Check out ember-app-kit , which uses qunit and the karma test runner. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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