javascript - Jasmine jQuery : loadFixtures() "undefined"?

标签 javascript jasmine

我的设置

  1. Win7/64位
  2. Wamp 服务器
  3. SublimeText 2

我做了什么...

  1. 通过 ruby​​ 加载 jasmine (jasmine init)
  2. 冉耙(耙 Jasmine )
  3. 删除了所有默认的公共(public) JavaScript、规范文件和帮助程序文件。
  4. 将 jquery 和 jasmine-jquery 添加到“helpers”目录
  5. 打开浏览器,启动 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();
    });
});

最佳答案

我认为您没有在这里测试您想要的内容。函数 setFixturesloadFixtures 没有返回值。这意味着当您调用 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/

相关文章:

javascript - 使用 Jasmine 对 api 的 promise 进行单元测试

javascript - spy 必须在之前的函数或规范中创建

Javascript 下一个/上一个脚本

javascript - JS - 通过对象的属性之一调用对象

javascript - 为什么在keydown回调中返回false并不会停止按钮点击事件?

coffeescript - 如何测试依赖于 ngResource 服务的 Controller

javascript - javascript 测试用例中的 BeforeAll 和 AfterAll

javascript - 我的项目使用代理跨域,但是当我请求它的请求地址改变

javascript - "appendTo"- 在 jQuery UI 中将可拖动对象连接到可排序元素时,方法无法正常运行

javascript - Angular 6 测试 Jasmine Karma : Override Provider Not working