我已经开始为我的js
文件编写测试,但我得到的是undefined
,我不指望它。这是我的代码:
describe('show jasmine testing', function() {
var x;
beforeEach(function() {
x = 3;
});
describe('booleans', function() {
it('should return true', function() {
expect(true).toBe(true);
});
});
describe('ints', function() {
console.log('This is x: ' + x);
expect(x).toBe(3);
});
});
在我的ints
测试中,我的x
变量为undefined
,因此测试始终失败。根据我的理解,它应该是3
,因为beforeEach
块在每个describe
块之前运行。我错过了什么?
答案 0 :(得分:5)
您需要将规范放在it
块中。每个规范都会运行beforeEach
。到描述运行时,您的beforeEach
尚未执行。