ember-cli-mirage icon indicating copy to clipboard operation
ember-cli-mirage copied to clipboard

Mirage doesn't work in engines tests.

Open luketheobscure opened this issue 5 years ago • 2 comments

Bug or question

When using a custom resolver (like what's recommended in the engines testing guide), ember-cli-mirage doesn't find the dummy config. The code where mirage registers the config does run, but it looks like it registers it with the wrong resolver.

I've got this working by manually registering the config before calling setupMirage:

// custom setupRendering test that sets the resolver
import setupRenderingTest from 'dummy/tests/helpers/setup-rendering-test';
import config from 'dummy/mirage/config';
import { setupMirage } from 'ember-cli-mirage/test-support';

module('Foo', function (hooks) {
  setupRenderingTest(hooks);
  hooks.beforeEach(function () {
    this.owner.register('mirage:base-config', config)
  });
  setupMirage(hooks);

  test('it renders', async function (assert) {
    await render(hbs`<MyDataLoadingComponent />`);

    assert.equal((this.element.textContent || '').trim(), 'Foo');
  });
});

luketheobscure avatar Sep 03 '19 23:09 luketheobscure

At the least we should document this.

Can I see the full resolver setup? I've never used engines so I'm not familiar.

samselikoff avatar Sep 15 '19 00:09 samselikoff

Here's the entirety of our setup-rendering-test file:

import { setupRenderingTest } from 'ember-qunit';
import engineResolverFor from 'ember-engines/test-support/engine-resolver-for';
import Resolver from 'dummy/resolver';

export default function (hooks: NestedHooks): void {
  const engineResolver = engineResolverFor('crop-records-engine');

  const resolver = Resolver.extend({
    namespace: { modulePrefix: 'dummy' },
    resolve() {
      const resolved = this._super(...arguments);
      if (resolved) {
        return resolved;
      }

      return engineResolver.resolve(...arguments);
    },
  }).create();

  return setupRenderingTest(hooks, { resolver });
}

luketheobscure avatar Sep 16 '19 22:09 luketheobscure