【问题标题】:How to use qunit-bdd with ember-qunit?如何将 qunit-bdd 与 ember-qunit 一起使用?
【发布时间】:2014-04-16 15:33:09
【问题描述】:

最初由 Andreas Haller 发布在邮件列表中,在此转发,以便其他人可以使用“qunit-bdd”标签。

ember-qunit 添加了一个方便的 moduleFor 助手,可以用作 QUnit 的 module 函数的替代方法。现在 ember-qunit 抽象了一些东西,这样我就不必使用模块功能,而且我不知道我是否可以。我的问题是双重的:

  1. describe 实际上的行为是否与module 相同?
  2. 如何使用 ember-qunit 的 moduleFor / moduleForComponent

如果 #2 没有解决方案,但像 describe(moduleFor('controller:posts'), function() { … }) 这样的东西会很好。

【问题讨论】:

标签: ember.js qunit-bdd ember-qunit


【解决方案1】:

qunit-bdd 中的describe 与 QUnit 中的module 的作用基本相同。不同之处在于它们可以嵌套在 qunit-bdd 中,并且每个嵌套级别将对应于 module 调用,并将名称连接在一起。例如,这将导致对module 的三个调用:

describe('Foo', function() {
  it('is a function', function() {
    expect(typeof Foo).to.equal('function');
  });

  describe('#foo', function() {
    it('says FOO', function() {
      expect(new Foo().foo()).to.equal('FOO');
    });
  });

  describe('#bar', function() {
    it('says BAR', function() {
      expect(new Foo().bar()).to.equal('BAR');
    });
  });
});

因为无法控制调用 module 函数的内容,所以(目前)还无法将 qunit-bdd 与 ember-qunit 一起使用。我们正在讨论如何改变这一点。您的建议可行,但需要为 ember-qunit 显式修改 qunit-bdd。我更喜欢在 ember-qunit 中拥有共享代码,然后为 qunit-bdd 提供一个瘦包装器。也许与您的类似,但保持 qunit-bdd 的 API 相同:

describe('PostsController', testFor('controller:posts', function() {
  it('has a length', function() {
    expect(this.subject.length).to.be.defined();
  });
}));

任何建议将不胜感激。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-08-16
    • 1970-01-01
    • 2014-01-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-01
    相关资源
    最近更新 更多