Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit testing routes? #38

Closed
mattmarcum opened this issue May 22, 2015 · 2 comments
Closed

Unit testing routes? #38

mattmarcum opened this issue May 22, 2015 · 2 comments
Labels

Comments

@mattmarcum
Copy link

Hi, I'm trying to unit test a route using ember-mocha. On the guides they show how to do this with the default q-unit framework, but I'm not sure ember-mocha is acting the same way. In the guide example this.subject() will return an instance of the module being tested. When I try to us emeber-mocha with a describeModule('route:someRoute'...) this.subject() returns the class and not an instance of the route like expected.

@kluzny
Copy link

kluzny commented May 11, 2016

Old issue is old, but here is how I did it:

 22 /* jshint expr:true */                                                                                                                                                                                                                                                                                                   
 21 import { expect } from 'chai';                                                                                                                                                                                                                                                                                           
 20 import { describeModule, it } from 'ember-mocha';                                                                                                                                                                                                                                                                        
 19 import { describe } from 'mocha';                                                                                                                                                                                                                                                                                        
 18 //import segmentStub from '../../helpers/segment-stub';                                                                                                                                                                                                                                                                  
 17                                                                                                                                                                                                                                                                                                                          
 16 describeModule.only(                                                                                                                                                                                                                                                                                                     
 15   'route:trades',                                                                                                                                                                                                                                                                                                        
 14   'Unit | Route | TradesController',                                                                                                                                                                                                                                                                                     
 13   function() {                                                                                                                                                                                                                                                                                                           
 12     describe('#tradesImported()', function() {                                                                                                                                                                                                                                                             
 11       it('refreshes the route', function() {                                                                                                                                                                                                                                                                             
 10         let route = this.subject();                                                                                                                                                                                                                                                                                      
  9         let refreshCalled = false;                                                                                                                                                                                                                                                                                       
  8         let oldRefresh = route.refresh;                                                                                                                                                                                                                                                                                  
  7         route.refresh = function() { refreshCalled = true; };                                                                                                                                                                                                                                                            
  6         route.send('tradesImported');                                                                                                                                                                                                                                                                                    
  5         route.refresh = oldRefresh;                                                                                                                                                                                                                                                                                      
  4         expect(refreshCalled).to.eq(true);                                                                                                                                                                                                                                                                               
  3       });                                                                                                                                                                                                                                                                                                                
  2     });                                                                                                                                                                                                                                                                                                                  
  1   }                                                                                                                                                                                                                                                                                                                      
23  );                                                                                                                                                                                                                                                                                                                       
~                          

@Turbo87
Copy link
Member

Turbo87 commented Nov 17, 2016

you can also have a look at the now official route-test blueprint for Mocha tests: https://github.com/emberjs/ember.js/blob/master/blueprints/route-test/mocha-files/tests/unit/__path__/__test__.js

@Turbo87 Turbo87 closed this as completed Nov 17, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants