2017-06-16 58 views
0

我创建了一个简单的JS 功能我想测试,但是当我运行它显示已被称为我在做什么错错误预计间谍日志?预计间谍日志

功能

function helloWorld() { 
    console.log('hey'); 
} 

测试规范

describe('Hello world', function() { 
    it('says hello', function() { 
     spyOn(console,'log').and.callThrough(); 
     expect(console.log).toHaveBeenCalled(); 
    }); 
}); 

回答

0

这是不是一个错误,这是一个失败的测试。这是因为您不会在您的示例中调用日志功能,因此测试“正确”失败。

describe('Hello world', function() { 
it('says hello', function() { 
    spyOn(console,'log').and.callThrough(); 
    comp.helloWorld(); 
    expect(console.log).toHaveBeenCalled(); 
    }); 
});