New test helper for getting the underlying CodeMirror instance from a dom selector

This commit is contained in:
Michael Lange 2018-08-16 10:56:37 -07:00
parent a96c4508d6
commit 9fb8964c00
3 changed files with 22 additions and 0 deletions

View File

@ -5,6 +5,7 @@ module.exports = {
selectSearch: true,
removeMultipleOption: true,
clearSelected: true,
getCodeMirrorInstance: true,
},
env: {
embertest: true,

View File

@ -0,0 +1,19 @@
import { registerHelper } from '@ember/test';
const invariant = (truthy, error) => {
if (!truthy) throw new Error(error);
};
export default function registerCodeMirrorHelpers() {
registerHelper('getCodeMirrorInstance', function(app, selector) {
const cmService = app.__container__.lookup('service:code-mirror');
const element = document.querySelector(selector);
invariant(element, `Selector ${selector} matched no elements`);
const cm = cmService.instanceFor(element.id);
invariant(cm, `No registered CodeMirror instance for ${selector}`);
return cm;
});
}

View File

@ -3,8 +3,10 @@ import { merge } from '@ember/polyfills';
import Application from '../../app';
import config from '../../config/environment';
import registerPowerSelectHelpers from 'ember-power-select/test-support/helpers';
import registerCodeMirrorHelpers from 'nomad-ui/tests/helpers/codemirror';
registerPowerSelectHelpers();
registerCodeMirrorHelpers();
export default function startApp(attrs) {
let attributes = merge({}, config.APP);