New test helper for getting the underlying CodeMirror instance from a dom selector
This commit is contained in:
parent
a96c4508d6
commit
9fb8964c00
|
@ -5,6 +5,7 @@ module.exports = {
|
|||
selectSearch: true,
|
||||
removeMultipleOption: true,
|
||||
clearSelected: true,
|
||||
getCodeMirrorInstance: true,
|
||||
},
|
||||
env: {
|
||||
embertest: true,
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
}
|
|
@ -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);
|
||||
|
|
Loading…
Reference in New Issue