Skip to content

Instantly share code, notes, and snippets.

@joegaudet
Last active November 8, 2017 17:50
Show Gist options
  • Save joegaudet/f9ff2a5c659507fb00d7851a66aecfe5 to your computer and use it in GitHub Desktop.
Save joegaudet/f9ff2a5c659507fb00d7851a66aecfe5 to your computer and use it in GitHub Desktop.
import Ember from 'ember';
import { before, beforeEach, afterEach, after } from 'mocha';
import { getContext } from 'ember-test-helpers';
export default function(Constructor) {
return function setupTest(moduleName, options = {}) {
var module;
var contextBefore;
if (Ember.typeOf(moduleName) === 'object') {
options = moduleName;
moduleName = '';
}
before(function() {
module = new Constructor(moduleName, options);
});
beforeEach(function() {
contextBefore = {};
return module.setup().then(() => {
var context = getContext();
Object.keys(context).forEach(key => {
contextBefore[key] = this[key];
this[key] = context[key];
});
});
});
afterEach(function() {
Object.keys(contextBefore).forEach(key => {
this[key] = contextBefore[key];
});
return module.teardown();
});
after(function() {
contextBefore = null;
module = null;
});
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment