Code Monkey home page Code Monkey logo

Comments (22)

briangonzalez avatar briangonzalez commented on May 22, 2024 2

@GCheung55

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.

alexander-alvarez avatar alexander-alvarez commented on May 22, 2024 1

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.

poteto avatar poteto commented on May 22, 2024

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.

poteto avatar poteto commented on May 22, 2024

@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.

briangonzalez avatar briangonzalez commented on May 22, 2024

@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.

briangonzalez avatar briangonzalez commented on May 22, 2024

This did not fix the issue.

from ember-metrics.

poteto avatar poteto commented on May 22, 2024

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:

  1. Are there any mixins involved, or is the component inheriting from another subclass of component?
  2. Are there services being injected into it that have the metrics service injected into them?
  3. Does the component have other components in its template, that use the metrics service?

from ember-metrics.

deepan83 avatar deepan83 commented on May 22, 2024

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.

briangonzalez avatar briangonzalez commented on May 22, 2024

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.

ashblue avatar ashblue commented on May 22, 2024

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.

poteto avatar poteto commented on May 22, 2024

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.

ashblue avatar ashblue commented on May 22, 2024

@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.

poteto avatar poteto commented on May 22, 2024

Interesting, thanks for finding that out! I will do an update to the README.

from ember-metrics.

briangonzalez avatar briangonzalez commented on May 22, 2024

Is there a better long term solution than moving all tracking to the route?

from ember-metrics.

poteto avatar poteto commented on May 22, 2024

I'll have to investigate, it's still odd that the router would be involved in a component unit / integration test.

from ember-metrics.

timjcook avatar timjcook commented on May 22, 2024

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.

briangonzalez avatar briangonzalez commented on May 22, 2024

@timjcook Mind sharing the mixin here?

from ember-metrics.

timjcook avatar timjcook commented on May 22, 2024

@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.

GCheung55 avatar GCheung55 commented on May 22, 2024

Just got bit by this issue.

from ember-metrics.

timjcook avatar timjcook commented on May 22, 2024

@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.

jherdman avatar jherdman commented on May 22, 2024

Is this still a relevant issue?

from ember-metrics.

jherdman avatar jherdman commented on May 22, 2024

Stale. Closing.

from ember-metrics.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.