我首先编写我的测试,我为方法编写的第一个测试是我希望它被定义。在我定义函数之前,我注意到这些断言正在传递。例如:
it "should be defined", () ->
expect(mySvc.foo).toBeDefined() # this passes when method is not defined
it "should return a promise", () ->
expect(mySvc.foo.then).toBeDefined() # this also passes when method is not defined
答案 0 :(得分:1)
必须有其他因素影响您的测试,因为此fiddle表明它没有通过。你有可能在相同的范围内定义它吗?
//这不会传递
describe('Jasmine test', function() {
it('should should be defined', function() {
expect(mySvc.foo).toBeDefined();
});
});
//通过
describe('Jasmine test', function() {
var mySvc = {
foo: "foo"
};
it('should should be defined', function() {
expect(mySvc.foo).toBeDefined();
});
});