Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
rwjblue opened this issue Oct 21, 2017 · 0 comments
Closed
Labels

Comments

@rwjblue
Copy link
Member

rwjblue commented Oct 21, 2017

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());
  });
});
@rwjblue rwjblue added the bug label Oct 21, 2017
@rwjblue rwjblue changed the title Other function properties in moduleFor* options are lost Non-lifecycle hook function properties in moduleFor* options are lost Oct 21, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant