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

contextualizeCallbacks prevents custom test instance helpers #204

Closed
jamesarosen opened this issue Apr 10, 2017 · 4 comments
Closed

contextualizeCallbacks prevents custom test instance helpers #204

jamesarosen opened this issue Apr 10, 2017 · 4 comments

Comments

@jamesarosen
Copy link

I want to write instance-level helper methods on a test class like so:

import Ember from 'ember';
import hbs from 'htmlbars-inline-precompile';
import { moduleForComponent, test } from 'ember-qunit';
const { run } = Ember;
let services;

moduleForComponent('service-authorizations', 'Integration: component:service-authorizations', {
  integration: true,

  fooBar(name) {
    return this.$(`.foo:contains(${name}) .bar`);
  },

  beforeEach() {
    this.render(hbs`{{foo-bar 1}} {{foo-bar 2}} {{foo-bar 3}}`);
  }
});

test('foo bars', function(assert) {
  assert.equal(this.fooBar(1).is(':disabled'), true);
  assert.equal(this.fooBar(2).is(':disabled'), false);
  assert.equal(this.fooBar(3).is(':disabled'), false);
});

contextualizeCallbacks memoizes anything I add in the moduleForComponent block and ignores arguments, so this.fooBar(2) returns the result from this.fooBar(1).

@jamesarosen
Copy link
Author

I can solve this by adding the methods in the beforeEach block instead of on the "prototype" object. It's just messier.

@Turbo87
Copy link
Member

Turbo87 commented Apr 11, 2017

Is functions on the objects being converted to methods on the context object officially supported API of this project?

@jamesarosen
Copy link
Author

Is functions on the objects being converted to methods on the context object officially supported API of this project?

Perhaps not. It seemed like an obvious thing to do to me.

@rwjblue
Copy link
Member

rwjblue commented Oct 14, 2017

Yeah, this is a major gotcha of the memoization system. The next iteration (from emberjs/rfcs#232) will not include this type of memoization.

I'm going to close this for now (since there really isn't much we can do about it in the current API)...

@rwjblue rwjblue closed this as completed Oct 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants