-
-
Notifications
You must be signed in to change notification settings - Fork 154
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
moduleForComponent issue with {{link-to}} helpers #52
Comments
I also got stuck on this, here is what I tried: moduleForComponent('super-component', "Unit - Component - Super", {
needs: [
'location:none',
'router:main',
],
setup: function () {
router.reopen({
location: 'none'
});
},
teardown: function () {
(...)
}
}); The error that I got is container.register('location:none', NoneLocation); Where That explains why this works flawlessly in integration tests but I am not sure how could this be made to work in unit tests. (NoneLocation is not accessible on the top-level Ember object or otherwise, to my knowledge). |
Hey Guys, Running into this exact same problem. The default test gives me the router error `import { test, moduleForComponent } from 'ember-qunit'`
moduleForComponent 'iteration-card', 'IterationCardComponent', {
# specify the other units that are required for this test
# needs: ['helper:link-to', 'router:main', 'location:auto']
}
test 'it renders', ->
expect 2
# creates the component instance
component = @subject()
equal component.state, 'preRender'
# appends the component to the page
@append()
equal component.state, 'inDOM' So I add router:main and get moduleForComponent 'iteration-card', 'IterationCardComponent', {
# specify the other units that are required for this test
needs: ['router:main']
}
test 'it renders', ->
expect 2 Any ideas on what to do here? @balinterdi have you gotten any further? |
@validkeys No, I bumped into the same problems you did and haven't found a way around them (it's either the "unknown factory: location:none" or the "auto is not a valid implementation" error. |
We're discussing this now at Ember Out East. This is really important to fix. |
👍 |
I believe that the plan is to use some sort of |
FWIW, I am running into this with an ember-cli addon that has it's own initializer. When I try to run integration tests on my main project, i get the unknown factory error. |
Sample app: https://github.com/dustinfarris/sample-app To reproduce: git clone git@github.com:dustinfarris/sample-app
cd sample-app && npm i && bower i
npm link ember-cli
ember t Output:
|
@rwjblue should I open a new issue for the above, or is it sufficiently related? |
This is still a problem. Has anybody figured out how to unit test a component with a |
@rwjblue, seems like this issue may have cropped up again. @devinus @chrisgame, I was able to get around it by adding this to my component test setup: moduleForComponent('my-component', 'Unit | Component | my component', {
unit: true,
setup: function () {
this.registry.register('service:-routing', Ember.Object.extend({
availableRoutes: function() { return ['index']; },
hasRoute: function(name) { return name === 'index'; },
isActiveForRoute: function() { return true; },
generateURL: function() { return "/"; }
}));
}
}); pulled from here: |
For what it's worth, we have had some success with implementing a stubbed helper in our testing: beforeSetup: ->
Ember.Handlebars.registerHelper('link-to', (value, options) ->
options.fn?() # this will just show the block |
@code0100fun That looks awesome! |
Just noting that is this still an issue with ember 1.13.0. The work around from @code0100fun works nicely though. |
Also seeing this issue with addon test suites running with Ember Try, which pulls |
There is a PR in Ember that fixes the error, and it should make it to the beta branch (for 2.0.0). |
@rwjblue - I couldn't find the PR to add this comment to, but this seems to be a breaking change in 1.13 (at least it broke my existing component tests). The workaround above works, but still seems like a regression. |
@jrjohnson I think we plan to do a few more 1.13 point releases. I wasn't sufficiently confident in the fix that I wanted to rush it into a point release, but if it lasts in beta/canary without any issues, I'm definitely not opposed to backporting it to a future 1.13 point release. |
Seems like @code0100fun is what works! |
You can use component integration tests for components with |
@code0100fun Sorry I wasn't clear, but testing the |
@rwjblue @code0100fun: Perfect, this is just what I needed, thanks a lot! |
@code0100fun @rwjblue I updated our application to Ember.js 2.1.1 and I am now getting an error message when running a component integration test that uses It fails at this line, where We updated to Ember.js 2.2 to see if it persisted and the same error still appears. Are you aware of any examples of using the router for component integration tests for Ember.js >= 2.1? |
@YoranBrondsema did you ever find a solution to the |
@trevorrjohn Unfortunately no. We needed to move on so decided to drop testing links in component integration tests. |
@YoranBrondsema @trevorrjohn I was able to get around the error by registering a stubbed application instance https://github.com/robwebdev/ember-cli-static-site/blob/b91075a92bc30038086fa7ae59961975c32ebcb9/tests/integration/components/link-to-test.js#L13 |
The actual {{link-to}} test works but getting some other strange issues. I'm seeing this error, anyone experiencing this:
Also another error along with it: |
Looks like by running: |
ping, seeing this issue in ember 2.12.2 still, after setting up the |
Sorry for letting this linger so long, this issue is quite out of date and likely the underlying problem has been fixed. Initial implementation of the new ember-qunit API (from emberjs/rfcs#232) has landed and will be included in 3.0.0 release soon. Closing as I do not believe that this issue can be addressed in the current ember-qunit@2 API. |
For people who would like a solution now, on Ember.js 2.16 I can run component integration tests that have moduleForComponent(
'component-with-link-to', '...', {
beforeEach() {
this.inject.service('-routing');
}
}
);
test(`the link goes to the 'abc' route`, async function(assert) {
this.render(hbs`
{{component-with-link-to}}
`);
const doTransition = this.stub(this.get('-routing'), 'doTransition');
await click('a');
assert.ok(doTransition.calledWith('abc'));
}); This example uses Sinon.js for stubbing. |
It seems when attempting to test components that contain a link-to helper, tests fail due to the absence of a router.
Here's a quick bin illustrating the issue:
http://jsbin.com/gapoqizo/3/edit
The text was updated successfully, but these errors were encountered: