Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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
Jasmine测试不起作用,期待间谍时未定义_Jasmine_Jasmine2.0 - Fatal编程技术网

Jasmine测试不起作用,期待间谍时未定义

Jasmine测试不起作用,期待间谍时未定义,jasmine,jasmine2.0,Jasmine,Jasmine2.0,我想用一个间谍来监视functino通话。但是我不能让它与我的代码一起工作 我的测试 it("calls the totalBogof() function", function() { spyOn(basket(), "totalBogof"); basket().total(); expect(basket.totalBogof).toHaveBeenCalled();

我想用一个间谍来监视functino通话。但是我不能让它与我的代码一起工作

我的测试

            it("calls the totalBogof() function", function() {
                spyOn(basket(), "totalBogof");
                basket().total();
                expect(basket.totalBogof).toHaveBeenCalled();
            });
我正在尝试测试的代码:

basket.prototype = {
    total: function(){
       var total=0.00;
       for(var i=0; i<shoppingBasket.length; i++){
            total += shoppingBasket[i].price;  
        }
         $('#total').html('total = '+currency+total.toFixed(2));
         this.totalBogof(total);
    },
    totalBogof: function(total){
         totalMinBOGOF = total - this.calcBOGOF();
         $('#total-bogof').html('Total - BOGOF = ' + currency + totalMinBOGOF.toFixed(2));
         this.totalPercentageDiscount(totalMinBOGOF, 10);
    },
}
basket.prototype={
总计:函数(){
var总计=0.00;

对于(var i=0;i你试过这个吗?看看那些间谍

5 specs, 1 failureSpec List | Failures
shoppingBasket calls the totalBogof() function
Error: Expected a spy, but got undefined.
Error: Expected a spy, but got undefined.
 at compare     (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:3083:17)
 at Expectation.toHaveBeenCalled     (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:1480:35)
 at Object.<anonymous> (file:///C:/Users/G/shoppingbasket-jasmine/shopping-basket.js:56:47)
 at attemptSync     (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:1886:24)
 at QueueRunner.run     (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:1874:9)
 at QueueRunner.execute (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:1859:10)
 at Spec.queueRunnerFactory (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:697:35)
 at Spec.execute (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:359:10)
 at Object.fn (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:2479:37)
 at attemptAsync (https://cdnjs.cloudflare.com/ajax/libs/jasmine/2.4.1/jasmine.js:1916:24)
it("calls the totalBogof() function", function() {
   spyOn(basket, "totalBogof");
   basket.total();
   expect(basket.totalBogof).toHaveBeenCalled();
});