我需要向要使用 Jasmine 测试的 Javascript 类添加功能。类定义是这样的:
GAME.Player.CustomPlayerSetup = function() {
...
};
如果我删除GAME.Player
,我可以编写正常的测试并让它们通过。但是当尝试离开Game.Player
CustomPlayerSetup 的类定义时,我得到一个 Reference Error Game is not defined。如何定义这个测试?
为了回答查尔斯的建议,即使我在我的 Jasmine 测试文件中声明 GAME 和 Player vars 在它仍然给我的 require 行之前,如
GAME = {};
GAME.Player = {};
CustomPlayerSetup = require("../CustomPlayerSetup").CustomPlayerSetup;
describe("Custom Player Setup", function() {
...
});
指向生产代码文件而不是测试文件的相同错误。我正在使用 jasmine-node 运行测试。