ember-codemods / ember-qunit-codemod

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-lifecycle hook function properties in moduleFor* options are lost

rwjblue opened this issue · comments

It is not uncommon to add properties to the options passed into the various moduleFor methods. In ember-qunit@2 any function properties added to that object were memoized, and any non-function properties were simply passed through to QUnit's module untouched.

I believe that we should remove this memoization while doing the transform (we can always disable it later if it seems trolling to folks).

Input:

moduleFor('service:foo', {
  buildWidget() {
    return someThing();
  }
});

test('can handle widgets', function(assert) {
  let subject = this.subject();
  let widget = this.buildWidget();
  subject.handleWidget(widget);
  assert.equal(widget, this.buildWidget());
});

Suggested output:

module('service:foo', function(hooks) {
  setupTest(hooks);
  
  function buildWidget() {
    return someThing();
  }

  test('can handle widgets', function(assert) {
    let subject = this.owner.lookup('service:foo');

    // when the function does not use `this`:
    let widget = buildWidget();

    // when the function does use `this`:
    let widget = buildWidget.call(this);

    subject.handleWidget(widget);
    assert.equal(widget, this.buildWidget());
  });
});