Skip to content

Instantly share code, notes, and snippets.

@kiwiupover
Last active March 6, 2018 19:30
Show Gist options
  • Save kiwiupover/8fdcd01b1a657f6f28643713f485818b to your computer and use it in GitHub Desktop.
Save kiwiupover/8fdcd01b1a657f6f28643713f485818b to your computer and use it in GitHub Desktop.
//tests/helpers/module-for-component.js
import getOwner from 'ember-owner/get';
import { moduleForComponent } from 'ember-qunit';
import freezeMoment from '../helpers/freeze-moment';
import moment from 'moment';
import {
setup as setupMirage, teardown as teardownMirage
} from 'marketplace-search/tests/helpers/setup-mirage';
export default function(name, description, callbacks) {
if (typeof description === 'object') {
callbacks = description;
description = undefined;
}
callbacks = callbacks || {};
if (!callbacks.hasOwnProperty('integration')) {
callbacks.integration = true;
}
let beforeEach = callbacks.beforeEach;
callbacks.beforeEach = function() {
this.owner = getOwner(this);
setupMirage(this, this.owner); // << updated here
this.store = this.owner.lookup('service:store');
if (beforeEach) {
return beforeEach.apply(this, arguments);
}
};
let afterEach = callbacks.afterEach;
callbacks.afterEach = function() {
teardownMirage(this);
if (afterEach) {
return afterEach.apply(this, arguments);
}
};
if (description) {
moduleForComponent(name, description, callbacks);
} else {
moduleForComponent(name, callbacks);
}
}
// integration/components/search-bar-test.js
import { test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import moduleForComponent from 'marketplace-search/tests/helpers/module-for-component';
moduleForComponent('search-bar', 'Integration | Component | search bar', {
integration: true
});
test('it renders', async function(assert) {
await this.server.createList('rental', 2);
this.render(hbs`{{search-bar}}`);
assert.elementCount(this.$('.search-bar'), 1);
});
// tests/helpers/setup-mirage.js
import mirageInitializer from 'marketplace-search/initializers/ember-cli-mirage';
import startMirage from 'ember-cli-mirage/start-mirage'; // << new use startMirage
/**
* These setup and teardown methods can be used to start a Mirage server
* in non-acceptance tests
*/
export function setup(testContext, owner) { // << new pass in the owner
mirageInitializer.initialize(testContext);
testContext.server = startMirage(owner);
}
export function teardown(testContext) {
if (testContext.server) {
testContext.server.shutdown();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment