Brian Donovan
Brian Donovan

Reputation: 8400

How to use qunit-bdd with ember-qunit?

Originally posted on the mailing list by Andreas Haller, reposting here so that the "qunit-bdd" tag will be available for others to use.

ember-qunit adds a handy moduleFor helper which one can use as an alternative to QUnit's module function. Now ember-qunit abstracts things so that i never have to use the module function and i don't know if i could. My question is twofold:

  1. Does describe defacto act the same as module?
  2. How can i use ember-qunit's moduleFor / moduleForComponent?

If there is no solution for #2 yet something like describe(moduleFor('controller:posts'), function() { … }) would be nice.

Upvotes: 3

Views: 522

Answers (1)

Brian Donovan
Brian Donovan

Reputation: 8400

describe in qunit-bdd does mostly act the same as module in QUnit. The difference is that they can be nested in qunit-bdd and each level of nesting will correspond to a module call with the names joined together. For example, this will result in three calls to 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');
    });
  });
});

Because there is no way to control what module function is called, there's no way (yet) to use qunit-bdd with ember-qunit. We are discussing how to change that. Your suggestion could work, but would require modification to qunit-bdd explicitly for ember-qunit. I'd prefer to have the shared code in ember-qunit and then have a thin wrapper for qunit-bdd. Perhaps something similar to yours, but keeping the API to qunit-bdd the same:

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

Any suggestions would be appreciated.

Upvotes: 2

Related Questions