我的设置
- Win7/64位
- Wamp 服务器
- SublimeText 2
我做了什么...
- 通过 ruby 加载 jasmine (jasmine init)
- 冉耙(耙 Jasmine )
- 删除了所有默认的公共(public) JavaScript、规范文件和帮助程序文件。
- 将 jquery 和 jasmine-jquery 添加到“helpers”目录
- 打开浏览器,启动 liveReload 并运行以下测试...
...其中,只有“readFixtures()”通过了。其他人都失败了。哇?请指教!
“readFixtures()”测试完美运行...
describe("test read fixtures", function() {
it("should be able to read fixtures", function() {
// expect(readFixtures()).toBeDefined();
expect(readFixtures()).toBeDefined();
});
});
“loadFixtures()”测试返回“预期未定义已定义。”
describe("test load fixtures", function() {
it("should be able to load fixtures", function() {
// expect(loadFixtures()).toBeDefined();
expect(loadFixtures()).toBeDefined();
});
});
“setFixtures()”测试返回“预期未定义已定义。”
describe("test set fixtures", function() {
it("should be able to set fixtures", function() {
// expect(setFixtures()).toBeDefined();
expect(setFixtures()).toBeDefined();
});
});
最佳答案
我认为您没有在这里测试您想要的内容。函数 setFixtures
和 loadFixtures
没有返回值。这意味着当您调用 setFixtures()
时,它将始终返回 undefined。 您想要测试函数是否已定义,而不是函数的返回值。您的测试应如下所示:
it("should be able to set fixtures", function() {
expect(setFixtures).toBeDefined(); // Notice I took out the ()
});
关于javascript - Jasmine jQuery : loadFixtures() "undefined"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13677559/