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

Add option to render to enable improved ember-engines testing API #795

Merged
merged 1 commit into from
Oct 6, 2021

Conversation

villander
Copy link
Contributor

@villander villander commented Apr 16, 2020

Add a second argument to render helper that can be used to specify a custom owner to be used for the provided template. This allows ember-engines to provide customized test setup code that users can use
to build and Engine instance and perform simpler rendering tests that from the context of that Engine.

When coupled with changes in ember-engines itself (ember-engines/ember-engines#653), an API similar to the following will be possible:

  module('setupEngineTest', function (hooks) {
    setupTest(hooks);
    setupEngine(hooks, 'my-engine-name');

    test('it exists', function (assert) {
      assert.expect(1);

      let route = this.engine.lookup('route:post.likes');
      assert.ok(route);
    });
  });

  module('setupEngineRenderingTest', function (hooks) {
    setupRenderingTest(hooks);
    setupEngine(hooks, 'my-engine-name');

    test('should change colors', async function(assert) {
      assert.expect(2);

      // set the outer context to red
      this.set('colorValue', 'red');

      await render(hbs`{{pretty-color name=colorValue}}`, { owner: this.engine });

      assert.equal(this.element.querySelector('div').getAttribute('style'), 'color: red', 'starts as red');

      this.set('colorValue', 'blue');

      assert.equal(this.element.querySelector('div').getAttribute('style'), 'color: blue', 'updates to blue');
    });
  });

@ef4

This comment has been minimized.

@villander

This comment has been minimized.

@rwjblue

This comment has been minimized.

@villander

This comment has been minimized.

@villander

This comment has been minimized.

@ef4

This comment has been minimized.

@villander

This comment has been minimized.

@ef4

This comment has been minimized.

@villander

This comment has been minimized.

Copy link
Contributor

@ef4 ef4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I was looking at only one of your commits, not all of them. And I was also reacting the code you pasted here in the comments, which I didn't realize isn't actually code in your PR.

tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
@villander

This comment has been minimized.

Copy link
Member

rwjblue commented Apr 20, 2020

We've landed a bunch of fixes to make CI more consistent (dropping Node < 10, reroll yarn.lock, etc), probably needs a rebase to kick things off again.

@villander

This comment has been minimized.

@villander

This comment has been minimized.

@villander villander requested a review from ef4 April 21, 2020 00:57
.eslintrc.js Outdated Show resolved Hide resolved
tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
tests/integration/ember-engines-test.js Outdated Show resolved Hide resolved
@villander
Copy link
Contributor Author

@rwjblue any chance to have a look here to make a progress?

@rwjblue
Copy link
Member

rwjblue commented Oct 6, 2021

I think this is good to go now!! Thanks @villander @richgt!

@rwjblue rwjblue changed the title Add support to Engines Add option to render to enable improved ember-engines testing API Oct 6, 2021
Add new `RenderOptions` option to be passed to `render`. This allows
ember-engines to provide customized test setup code that users can use
to build and Engine instance and perform simpler rendering tests
that from the context of that Engine.

Co-Authored-By: Rich Glazerman <rglazerman@squareup.com>
Co-Authroed-By: Robert Jackson <me@rwjblue.com>
@@ -28,6 +29,36 @@ import {
} from '../helpers/resolver';
import { hbs } from 'ember-cli-htmlbars';
import { getOwner } from '@ember/application';
import Engine from '@ember/engine';

async function buildEngineOwner(parentOwner, registry) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rwjblue rwjblue merged commit 2347b8f into emberjs:master Oct 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants