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

Does delegate functionality still exist in moduleFor? #112

Closed
theworkerant opened this issue Dec 2, 2014 · 6 comments
Closed

Does delegate functionality still exist in moduleFor? #112

theworkerant opened this issue Dec 2, 2014 · 6 comments

Comments

@theworkerant
Copy link

Situation: I'm trying to setup my controller of interest using moduleFor with a model. So I'm looking at moduleForModel I see this.store() grabs it. In moduleFor this.store() is undefined. Although I'm not sure how to use it, I thought delegate might be the solution here as opposed hacking around in the container. Contrary to the docs, delegate is undefined.

As listed in the docs

delegate: To manually modify the container & the testing context, supply a function as the delegate matching this signature delegate(container, testing_context)

Perhaps these docs were copied directly from Ember App Kit and something got changed in between? I can't seem to find any other info on this. Anyone got ideas on best practices here?


originally posted here for reference: ember-cli/ember-cli#2620

@jakecraige
Copy link

The docs referenced can be found in ember-cli here

@matthiasleitner
Copy link

@rwjblue the delegate functionality is gone in the > 0.2.0 versions right?

@cristinawithout
Copy link

Looking at the code, it does appear that delegate was removed in 0.2.0. Though the documentation still references it.

We just recently upgraded and have controller unit tests that used delegate to register a service and dependency injection on the controller that's done in initializers, which aren't loaded into the controller's unit tests.

With delegate removed, I'm unable to find a method of doing dependency injection on the controller's unit tests.

This is a simplified version of the code we used prior to v0.2.0 which worked well.

import myService from 'my-add-on/services/my-service';

moduleFor(
    'controller:mine'
    'Unit: Controller: My Controller', 
    {
        needs: ['controller:another']
    }, 
    function(container, testing_context) {
        container.register('service:my-service, myService, {instantiate: true, singleton: false}); 
        container.injection('controller', 'myService', 'service:my-service');
    }
);

I tried doing the injection via the app and the container in beforeEach but the myService property remains undefined on the controllers during the tests.

Here's an example of those failed attempts:

import myService from 'my-add-on/services/my-service';
import startApp from '../../helpers/start-app';

moduleFor(
    'controller:mine'
    'Unit: Controller: My Controller', 
    {
        needs: ['controller:another'],
        beforeEach: function() {
            var App = startApp();
            App.register('service:my-service', myService, {instantiate: true, singleton: false});
            App.inject('controller', 'myService', 'service:my-service');
        }
    }
);
import myService from 'my-add-on/services/my-service';
import startApp from '../../helpers/start-app';

moduleFor(
    'controller:mine'
    'Unit: Controller: My Controller', 
    {
        needs: ['controller:another'],
        beforeEach: function() {
            var App = startApp();
            App.__container__.register('service:my-service', myService, {instantiate: true, singleton: false});
            App.__container__.injection('controller', 'myService', 'service:my-service');
        }
    }
);

@sohara
Copy link

sohara commented May 5, 2015

I encountered this issue and found that collaborators (mocked/stubbed or otherwise) could be injected in controllers or other objects under test like so:

import myService from '../../app/services/my-service';

moduleFor('controller:mine', {
  beforeEach: function() {
    this.container.register('service:mine', myService,
      { singleton: true,
        instantiate: false
      });
    this.container.injection('controller', 'myService', 'service:mine');
  }
});

Basically, the test container exists on the scope for both the moduleFor callbacks and the test function.

@cristinawithout
Copy link

Thanks, sohara. That works and solves being able to register services on unit tests without delegate.

theworkerant's issue of not having the store isn't solved with that, but I found similar issues (https://github.com/rwjblue/ember-qunit/issues/70, https://github.com/rwjblue/ember-qunit/issues/108) that were closed with https://github.com/rwjblue/ember-qunit/issues/153

@Turbo87
Copy link
Member

Turbo87 commented Oct 14, 2017

this seems no longer relevant, closing due to age

@Turbo87 Turbo87 closed this as completed Oct 14, 2017
Turbo87 pushed a commit that referenced this issue Oct 19, 2018
Bumps [lerna-changelog](https://github.com/lerna/lerna-changelog) from 0.7.0 to 0.8.2.
<details>
<summary>Release notes</summary>

*Sourced from [lerna-changelog's releases](https://github.com/lerna/lerna-changelog/releases).*

> ## v0.8.2
> #### 🐛 Bug Fix
> * [#125](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/125) Fix `nextVersion` config handling ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🏠 Internal
> * [#124](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/124) yarn: Add `integrity` hashes ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### Committers: 1
> - Tobias Bieniek ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> ## v0.8.1
> #### 🚀 Enhancement
> * [#117](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/117) Allow "Unreleased" commit group to be renamed ([[**alex-pex**](https://github.com/alex-pex)](https://github.com/alex-pex))
> 
> #### 📝 Documentation
> * [#120](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/120) Add monorepo support docs ([[**jonaskello**](https://github.com/jonaskello)](https://github.com/jonaskello))
> 
> #### Committers: 2
> - Alexandre Paixao ([[**alex-pex**](https://github.com/alex-pex)](https://github.com/alex-pex))
> - Jonas Kello ([[**jonaskello**](https://github.com/jonaskello)](https://github.com/jonaskello))
> 
> 
> ## v0.8.0
> #### 💥 Breaking Change
> * [#92](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/92) Declare Node version support (6+). ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🚀 Enhancement
> * [#115](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/115) Improve CLI help output ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#114](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/114) Add `--from` and `--to` as replacements for `--tag-from/to` ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#108](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/108) Improve progress reporting ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#105](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/105) Ignore dependency update bots by default ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#103](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/103) Use `cli-highlight` to syntax highlight markdown output. ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#102](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/102) Improve automatic config detection. ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🐛 Bug Fix
> * [#116](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/116) Fix progress bar rendering for `--no-color` ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#107](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/107) Fix `refName` parsing ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#106](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/106) Remove trailing period enforcement from PR titles ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#104](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/104) Add `@` sign in front of contributor login ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 📝 Documentation
> * [#113](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/113) Update Documentation ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🏠 Internal
> * [#111](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/111) Update `progress` to v2.0.0 ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#112](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/112) Update `rimraf` to v2.6.2 ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#110](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/110) Update `p-map` to v1.2.0 ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#109](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/109) Update `yargs` to v11.0.0 ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#101](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/101) CI: Remove `node_modules` from cache. ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#100](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/100) package.json: Adjust changelog labels. ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
></table> ... (truncated)
</details>
<details>
<summary>Changelog</summary>

*Sourced from [lerna-changelog's changelog](https://github.com/lerna/lerna-changelog/blob/master/CHANGELOG.md).*

> ## v0.8.2 (2018-10-14)
> 
> #### 🐛 Bug Fix
> * [#125](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/125) Fix `nextVersion` config handling ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🏠 Internal
> * [#124](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/124) yarn: Add `integrity` hashes ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### Committers: 1
> - Tobias Bieniek ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> 
> ## v0.8.1 (2018-10-10)
> 
> #### 🚀 Enhancement
> * [#117](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/117) Allow "Unreleased" commit group to be renamed ([[**alex-pex**](https://github.com/alex-pex)](https://github.com/alex-pex))
> 
> #### 📝 Documentation
> * [#120](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/120) Add monorepo support docs ([[**jonaskello**](https://github.com/jonaskello)](https://github.com/jonaskello))
> 
> #### Committers: 2
> - Alexandre Paixao ([[**alex-pex**](https://github.com/alex-pex)](https://github.com/alex-pex))
> - Jonas Kello ([[**jonaskello**](https://github.com/jonaskello)](https://github.com/jonaskello))
> 
> 
> ## v0.8.0 (2018-06-19)
> 
> #### 💥 Breaking Change
> * [#92](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/92) Declare Node version support (6+). ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🚀 Enhancement
> * [#115](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/115) Improve CLI help output ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#114](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/114) Add `--from` and `--to` as replacements for `--tag-from/to` ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#108](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/108) Improve progress reporting ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#105](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/105) Ignore dependency update bots by default ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#103](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/103) Use `cli-highlight` to syntax highlight markdown output. ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#102](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/102) Improve automatic config detection. ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🐛 Bug Fix
> * [#116](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/116) Fix progress bar rendering for `--no-color` ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#107](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/107) Fix `refName` parsing ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#106](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/106) Remove trailing period enforcement from PR titles ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#104](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/104) Add `@` sign in front of contributor login ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 📝 Documentation
> * [#113](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/113) Update Documentation ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> 
> #### 🏠 Internal
> * [#111](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/111) Update `progress` to v2.0.0 ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
> * [#112](https://github-redirect.dependabot.com/lerna/lerna-changelog/pull/112) Update `rimraf` to v2.6.2 ([[**Turbo87**](https://github.com/Turbo87)](https://github.com/Turbo87))
></table> ... (truncated)
</details>
<details>
<summary>Commits</summary>

- [`8ae7803`](lerna/lerna-changelog@8ae7803) v0.8.2
- [`01ac435`](lerna/lerna-changelog@01ac435) Update Changelog
- [`17b2a9c`](lerna/lerna-changelog@17b2a9c) Merge pull request [#125](https://github-redirect.dependabot.com/lerna/lerna-changelog/issues/125) from Turbo87/config-fix
- [`dfe0b1d`](lerna/lerna-changelog@dfe0b1d) Fix `nextVersion` config handling
- [`958dc28`](lerna/lerna-changelog@958dc28) Merge pull request [#124](https://github-redirect.dependabot.com/lerna/lerna-changelog/issues/124) from Turbo87/integrity
- [`e135748`](lerna/lerna-changelog@e135748) yarn: Add `integrity` hashes
- [`17c835d`](lerna/lerna-changelog@17c835d) v0.8.1
- [`15b8076`](lerna/lerna-changelog@15b8076) Update Changelog
- [`35b6fa8`](lerna/lerna-changelog@35b6fa8) Add monorepo support docs ([#120](https://github-redirect.dependabot.com/lerna/lerna-changelog/issues/120))
- [`6fc2941`](lerna/lerna-changelog@6fc2941) Merge pull request [#117](https://github-redirect.dependabot.com/lerna/lerna-changelog/issues/117) from alex-pex/feature/set-next-version
- Additional commits viewable in [compare view](lerna/lerna-changelog@v0.7.0...v0.8.2)
</details>
<br />

[![Dependabot compatibility score](https://api.dependabot.com/badges/compatibility_score?dependency-name=lerna-changelog&package-manager=npm_and_yarn&previous-version=0.7.0&new-version=0.8.2)](https://dependabot.com/compatibility-score.html?dependency-name=lerna-changelog&package-manager=npm_and_yarn&previous-version=0.7.0&new-version=0.8.2)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

Dependabot will **not** automatically merge this PR because it includes an out-of-range update to a development dependency.

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot ignore this [patch|minor|major] version` will close this PR and stop Dependabot creating any more for this minor/major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Automerge options (never/patch/minor, and dev/runtime dependencies)
- Pull request limits (per update run and/or open at any time)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)

Finally, you can contact us by mentioning @dependabot.

</details>
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

6 participants