访问未在Ember App中定义

时间:2014-04-28 13:18:25

标签: ruby-on-rails ember.js

我正在尝试使用Ember和Konacha进行一些TDD - 当我尝试使用访问时出现此错误

ReferenceError: visit is not defined
at Context.<anonymous> (http://localhost:3500/assets/api_spec.js?body=1:24:5)
at Test.Runnable.run (http://localhost:3500/assets/mocha.js:4336:32)
at Runner.runTest (http://localhost:3500/assets/mocha.js:4724:10)
at http://localhost:3500/assets/mocha.js:4802:12
at next (http://localhost:3500/assets/mocha.js:4649:14)
at http://localhost:3500/assets/mocha.js:4659:7
at next (http://localhost:3500/assets/mocha.js:4597:23)
at http://localhost:3500/assets/mocha.js:4621:7
at Hook.Runnable.run (http://localhost:3500/assets/mocha.js:4338:5)
at next (http://localhost:3500/assets/mocha.js:4609:10)

api_spec.rb

//= require spec_helper                                                                                                                                                                                                      
describe("fake server", function() {                                                                                                                                                                        

    beforeEach(function() {                                                                                                                                                                             
       this.server = sinon.fakeServer.create();                                                                                                                                                         
    });                                                                                                                                                                                                 
    afterEach(function() {                                                                                                                                                                              
      this.server.restore();                                                                                                                                                                            
    });                                                                                                                                                                                                 
    it("#transition off Landing", function() {                                                                                                                                                          
       visit("/").then(function() {                                                                                                                                                                     
            var mock = sinon.mock(testHelper.lookup('route', 'index'));                                                                                                                                 
            mock.expects('transitionTo').once();                                                                                                                                                        
            mock.verify();                                                                                                                                                                              
            mock.restore();                                                                                                                                                                             
       });                                                                                                                                                                                              
    });                                                                                                                                                                                                         
}

这是我的spec_helper.rb

//= require sinon
//= require ember-mocha-adapter
//= require application

mocha.ui('bdd');                                                                                                                                                                                          
mocha.globals(['Ember', 'App', 'DS', 'MD5']);                                                                                                                                                             
mocha.timeout(500);                                                                                                                                                                                       
chai.Assertion.includeStack = true;                                                                                                                                                                       

ENV =                                                                                                                                                                                                     
{                                                                                                                                                                                                         
   TESTING:true                                                                                                                                                                                           
};                                                                                                                                                                                                        

window.server = sinon.fakeServer.create();                                                                                                                                                                

window.testHelper = {                                                                                                                                                                                     
  lookup: function(object, object_name) {                                                                                                                                                                 
    name = object_name || "main";                                                                                                                                                                         
    return App.__container__.lookup(object + ":" + name);                                                                                                                                                 
  }                                                                                                                                                                                                       
}                                                                                                                                                                                                         

App.Router.reopen({                                                                                                                                                                                       
  location: 'none'                                                                                                                                                                                        
});                                                                                                                                                                                                       

Konacha.reset = Ember.K;    

如何通过访问让ember玩得很好?

干杯!

1 个答案:

答案 0 :(得分:1)

visit仅在您致电

时注入
App.injectTestHelpers();

此外,您必须运行Ember的调试版本。

但它只适用于qunit,如果你使用不同的测试框架,你需要编写自己的visit