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

moduleForMixin? #15

Closed
coderberry opened this issue Mar 26, 2014 · 18 comments
Closed

moduleForMixin? #15

coderberry opened this issue Mar 26, 2014 · 18 comments

Comments

@coderberry
Copy link

I think we may need a moduleForMixin

@ryanflorence
Copy link
Contributor

What mixins are looked up on the container? Can't we just unit test these like any old js object?

@coderberry
Copy link
Author

I guess I just need to come up with a good example of doing this. In this example I am needing to test a controller that uses the mixin in order to get the mixin functionality. The mixin references 'content' which resides on a controller that extends it. I suppose I could stub out a controller and have it extend the mixin under test. That's probably the best way, but if it is, should there be a shortcut to do this via ember-qunit?

http://jsbin.com/cahuc/1/edit

@ryanflorence
Copy link
Contributor

Mixins don't get registered on the container, so testing them is like testing any old non-ember thing.

module('some mixin');
test('stuff', function() {
  equal(MyMixin.foo(), 'foo');
});

@stefanpenner
Copy link
Member

we could still resolve them, which follows the same pattern as everything else.

moduleFor('mixin:foo') should "just work"

@knomedia
Copy link

@cavneb in your specific case (mixin is counting on properties being defined on the mixed-in context). I'd just create a dummy Ember.Object with those parts:

http://jsbin.com/rehihane/1/edit

Otherwise +1 to moduleFor('mixin:foo')

@coderberry
Copy link
Author

I think part of what we are wanting is shortcuts so people don't have to think about the setup any more than they have to. It would be ideal for moduleFor('mixin:foo') to do something like what @knomedia's jsbin shows.

@andremalan
Copy link

Yeah, I don't think one needs to assume that moduleFor is looking in the container, the structure makes it feel like you could look up any type of Ember Object and it should do the correct thing by default.

@tonycoco
Copy link

tonycoco commented May 8, 2014

It would be nice if moduleForMixin gave you back an empty Ember.Object with the mixin mixed in and attached to the this.subject()

@jacefarm
Copy link

+1

@rwjblue
Copy link
Member

rwjblue commented Oct 29, 2014

I think that the pattern that ember-cli uses for this is the right way to go:

import Ember from 'ember';
import MySpecialMixin from '../mixins/my-special';

module('MySpecialMixin');

// Replace this with your real tests.
test('it works', function() {
  var MySpecialObject = Ember.Object.extend(MySpecialMixin);
  var subject = MySpecialObject.create();
  ok(subject);
});

@rwjblue rwjblue closed this as completed Oct 29, 2014
@tonycoco
Copy link

I thought this would be best too. Thanks for documenting it here, @rwjblue

@SirZach
Copy link

SirZach commented Nov 1, 2014

@rwjblue thanks for the demo on how to do this in ember-cli. I don't know if you're trying to prevent the docs from getting too unwieldy but I think this would be a great candidate to go on ember-cli.com.

@rwjblue
Copy link
Member

rwjblue commented Nov 1, 2014

@SirZach - 'ember generate mixin foo' does this for you automatically.

@SirZach
Copy link

SirZach commented Nov 1, 2014

@rwjblue that's awesome. ember-cli continues to impress

@BryanCrotaz
Copy link
Contributor

module('') appears to be deprecated in 0.2.0

@rwjblue
Copy link
Member

rwjblue commented Mar 18, 2015

0.2.0 of what project? module is not deprecated to my knowledge...

@BryanCrotaz
Copy link
Contributor

@rwjblue
Sorry, ember-cli 0.2.0. See ember-cli/ember-cli#3557
I'm using

moduleFor('mixin:foo');

as a replacement

@ghost
Copy link

ghost commented Oct 25, 2016

@rwjblue I'm writing some unit tests for a mixin right now and I keep getting get is undefined whenever I try and use this.get within my mixin. When I inspect the mixin object that was created, it only contains the properties defined in the mixin even though I have extended the Ember.Object class:

mixin = Ember.Object.extend(MyMixin)
mixin.get('hello') // => is undefined and results in error

How do I make sure I have computed properties, get/set available?

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

10 participants