2014-02-06 28 views
2

案例

当我创建rootScope间谍,期望某种原因失败。检查一下plunkr,然后试着评论一下,然后倒车看看。茉莉花spyOn范围功能测试断裂

代码

Plunker Example

describe('Testing', function() { 
    var rootScope = null 

    //you need to indicate your module in a test 
    // beforeEach(module('plunker')); 

    beforeEach(inject(function($rootScope, $controller) { 
    rootScope = $rootScope; 

    rootScope.value = false; 

    rootScope.testFn = function() { 
     rootScope.value = true; 
    } 
    })); 

    it('should modify root scope', function() { 
    // Creating this spy makes test fail 
    // Comment it outto make it pass 
    spyOn(rootScope, 'testFn'); 
    expect(rootScope.value).toEqual(false); 
    rootScope.testFn(); 
    expect(rootScope.value).toEqual(true); 
    }); 
}); 

回答