我的测试失败,原因如下:
ReferenceError:找不到变量:文件中的moving_canvas_context(第5行)
我理解测试失败的原因。它不理解该变量,因为它是在单独的 JavaScript 文件中定义的。但是,它是全局声明的,并且在现实中有效。
如何为此clear_canvas
功能编写茉莉花测试?
JavaScript Canvas_Actions
:
(function() {
window.Canvas_Actions = (function() {
function Canvas_Actions() {}
Canvas_Actions.prototype.clear_canvas = function() {
moving_canvas_context.clearRect(0, 0, moving_canvas.width, moving_canvas.height);
main_canvas_context.drawImage(window.background_image, 0, 0, main_canvas.width, main_canvas.height);
return window.canvas_objects = [];
};
return Canvas_Actions;
})();
}).call(this);
茉莉花测试Canvas_Actions
:
(function() {
describe('Canvas Actions', function() {
return describe('clear_canvas', function() {
return it('clears the canvases and deletes all objects', function() {
var actions;
jasmine.getFixtures().fixturesPath = "../spec/javascript/fixtures";
loadFixtures("canvas_fixture.html");
actions = new Canvas_Actions();
actions.clear_canvas();
return expect(canvas_objects).toEqual([]);
});
});
});
}).call(this);