ember-debug-logger icon indicating copy to clipboard operation
ember-debug-logger copied to clipboard

Testing Components that use ember-debug-logger

Open rstudner opened this issue 9 years ago • 1 comments

I have a component, I happily have this.debug("yay!"); inside of it.

When I run the test for the component I see:

        Died on test #1 http://localhost:7357/assets/tests.js:1175:24
        exports@http://localhost:7357/assets/vendor.js:140:37
        requireModule@http://localhost:7357/assets/vendor.js:32:25
        require@http://localhost:7357/assets/test-support.js:7124:14
        loadModules@http://localhost:7357/assets/test-support.js:7116:21
        load@http://localhost:7357/assets/test-support.js:7146:33
        http://localhost:7357/assets/test-support.js:7030:22: undefined is not a constructor (evaluating 'this.debug("yay!")')
    Log: |
...

any simple recommended way to get around this?

(i've tried the simple this.set('debug', etc); to no avail)

rstudner avatar Jan 27 '17 20:01 rstudner

Unfortunately the way this addon relies on an instance initializer right now makes this a little tricky to pull off. I think something like this ought to work in a component test, though:

import { initialize } from 'ember-debug-logger/instance-initializers/debug-logger';

// ...

beforeEach() {
  initialize(Ember.getOwner(this));
}

The better approach from this end might be to just reopen the relevant classes in a bare module, so you could just import it for the side effect in your test-helper.js. I'll plan to investigate that when I get a chance, but I'd also happily accept a PR in the meantime :)

dfreeman avatar Jan 30 '17 15:01 dfreeman