Last active
November 8, 2017 17:50
-
-
Save joegaudet/f9ff2a5c659507fb00d7851a66aecfe5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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