Comments (22)
We've gotten around this issue using blueprints at Dollar Shave Club:
my-app/blueprints/route-test/files/tests/unit/routes/__test__.js
import { moduleFor, test } from 'ember-qunit';
import TestConfig from 'my-app/tests/config';
moduleFor('route:<%= dasherizedModuleName %>', {
needs: TestConfig.defaultRouterNeeds.concat([
// Specify the other units that are required for this test.
]),
});
// Replace this with your real tests.
test('it exists', function itExists(assert) {
const route = this.subject();
assert.notOk(route, 'It shoud have a real test');
});
from ember-metrics.
unless need to verify that the page transitions are working in your tests, I worked around it like so
router.js
if (config.environment !== 'test') {
ApplicationRouter.reopen({
metrics: inject.service(),
...
});
}
from ember-metrics.
If you're using a method on the service in a component/controller/route/etc, you'll need to inject it via needs
in your test. If you're not, then I suspect it is due to the augmented LinkComponent
(i.e. you have a link-to in your component template), which I am considering removing.
from ember-metrics.
@briangonzalez If you'd like, you can give 5b1327d a try and see if that helps with your tests.
Edit: 0.4.0
from ember-metrics.
@poteto Thanks for the quick turnaround!
If you're using a method on the service in a component/controller/route/etc, you'll need to inject it via needs
We're not, so this is most likely a bug.
@cacuario and I are going to give this a shot tomorrow and we'll keep you posted.
from ember-metrics.
This did not fix the issue.
from ember-metrics.
Something in your component(s) is using the metrics service, it would not throw otherwise. The addon doesn't do any automatic dependency injection into components, so that is an Ember semantic that is entirely opt-in. It is hard to say without knowing the details of the component(s), but perhaps you could try checking:
- Are there any mixins involved, or is the component inheriting from another subclass of component?
- Are there services being injected into it that have the metrics service injected into them?
- Does the component have other components in its template, that use the metrics service?
from ember-metrics.
I've injected the service into my router to report route transitions to google analytics and unit tests on routes and controllers that don't explicitly inject the service are failing. Is specifying the service as a dependency on these tests through needs the only way of addressing this?
from ember-metrics.
Yes, 100%.
On Monday, February 22, 2016, Deepan Aiyasamy [email protected]
wrote:
I've injected the service into my router to report route transitions to
google analytics and unit tests on routes and controllers that don't
explicitly inject the service are failing. Is specifying the service as a
dependency on these tests through needs the only way of addressing this?—
Reply to this email directly or view it on GitHub
#43 (comment)
.
–
Brian
from ember-metrics.
We started cleaning up our tests and found this was the cause of 100 failed tests. If we can't fix this easily we'll have to abandon the plugin. Having to inject a need into every test is a rough solution.
Actually is it possible to write an Ember Test Helper to easily solve this issue (new to Ember testing so I apologize for anything that doesn't make sense with what I'm saying.
from ember-metrics.
That is definitely very odd. If you move the page transition track in the router into the application route instead, does the needs still occur?
@ashblue Are you using the service at all in the tests that are failing?
from ember-metrics.
@poteto Awesome! That magically seems to have fixed it. Still crawling through the error logs for some other issues, but everything looks smooth.
from ember-metrics.
Interesting, thanks for finding that out! I will do an update to the README.
from ember-metrics.
Is there a better long term solution than moving all tracking to the route?
from ember-metrics.
I'll have to investigate, it's still odd that the router would be involved in a component unit / integration test.
from ember-metrics.
We had the same issue, injecting the service into the router broke a lot of unit tests.
We ended up writing a mixin that binds our metrics events to the Route#activate
hook and included it on all routes that we needed it for. Works well and I kind of like a Route
being in control of sending its own events.
from ember-metrics.
@timjcook Mind sharing the mixin here?
from ember-metrics.
@briangonzalez mixin for basic page tracking looks like this
import Ember from 'ember';
export default Ember.Mixin.create({
metrics: Ember.inject.service(),
trackCurrentPage: Ember.on('activate', function () {
Ember.run.scheduleOnce('afterRender', this, () => {
const page = document.location.pathname;
const title = this.getWithDefault('routeName', 'unknown');
Ember.get(this, 'metrics').trackPage({ page, title });
});
})
});
props to @antonivanopoulos
from ember-metrics.
Just got bit by this issue.
from ember-metrics.
@nishant011093 best way to get an answer in these forums is to have a conversation, not just copy paste code 😄 Feel free to tag me if you want to explain you issue further. Good luck.
from ember-metrics.
Is this still a relevant issue?
from ember-metrics.
Stale. Closing.
from ember-metrics.
Related Issues (20)
- Resolve ember-beta and ember-canary fails HOT 2
- Deprecate EmberObject Usage? HOT 15
- 😍 TypeScript 😍 HOT 1
- [1.3.0] GoogleTagManager script tag included twice HOT 2
- NOTICE: Intent to rename primary branch HOT 2
- Deprecate Metrics Service `options`
- Support Embroider optimized HOT 2
- Outdated metrics-adapter test blueprint
- Investigate spurious facebook adapter fail
- Refactor Adapter Hook Methods HOT 6
- Support for Google Analytics 4 HOT 7
- Modernize Segment Tests
- `this._adapters` is not iterable in `willDestory` hook
- Breaking changes in 1.4.x HOT 2
- Why does the GTM adapter rewrite top-level event schema in trackEvent? HOT 5
- Release 1.5.0 accidentally shipped breaking changes meant for v2? HOT 5
- deprecation message says "This will be removed in Ember 2.0.0"
- Google Tag Manager Crossorigin
- SetCustomVariables for Piwik adapter
- Metrics adapters no longer inject services.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ember-metrics.