Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/412.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript EmberJs+;未使用正确的对象调用Sinon存根_Javascript_Unit Testing_Ember.js_Qunit_Sinon - Fatal编程技术网

Javascript EmberJs+;未使用正确的对象调用Sinon存根

Javascript EmberJs+;未使用正确的对象调用Sinon存根,javascript,unit-testing,ember.js,qunit,sinon,Javascript,Unit Testing,Ember.js,Qunit,Sinon,我有下面的代码测试是否调用了正确的操作方法,但是在设置中,似乎生成了不同的控制器实例,因此测试失败。任何提示都会有帮助 module('SearchViewtests', { setup : function() { App.reset(); Ember.run(this, function(){ this.controller = App.SearchController.create({ }); sinon.stub(t

我有下面的代码测试是否调用了正确的操作方法,但是在设置中,似乎生成了不同的控制器实例,因此测试失败。任何提示都会有帮助

module('SearchViewtests', {
setup : function() {

    App.reset();

    Ember.run(this, function(){

        this.controller = App.SearchController.create({
        });

        sinon.stub(this.controller._actions, "search");

        this.view = App.SearchView.create({
            controller : this.controller,
            container : App.__container__,
            context : this.controller
        });

        this.view.append();
    });
},
teardown : function(){
    Ember.run(this, function () {
        this.view.remove(); 
    });
    this.controller._actions.search.restore();
}});

test("on search button click invokes search action on controller", function(){

var button = this.view.$(".searchButton:button");

button.trigger('click');

ok(this.controller._actions.search.calledOnce, "Search page called");
});

使用一个上下文,而不是设置
和测试

test("on search button click invokes search action on controller",
  function(){

   var button = this.view.$(".searchButton:button");

   button.trigger('click');

   this.controller = App.SearchController.create({
    });

    sinon.stub(this.controller._actions, "search");

    this.view = App.SearchView.create({
        controller : this.controller,
        container : App.__container__,
        context : this.controller
    });

    this.view.append();
   ok(this.controller._actions.search.calledOnce, "Search page called");
});