e60b16a7e0
This exports a function that returns the pertinent function when given a container. This way it works in registerHelper and in integration tests beforeEach hooks
27 lines
763 B
JavaScript
27 lines
763 B
JavaScript
import { registerHelper } from '@ember/test';
|
|
|
|
const invariant = (truthy, error) => {
|
|
if (!truthy) throw new Error(error);
|
|
};
|
|
|
|
export function getCodeMirrorInstance(container) {
|
|
return function(selector) {
|
|
const cmService = 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;
|
|
};
|
|
}
|
|
|
|
export default function registerCodeMirrorHelpers() {
|
|
registerHelper('getCodeMirrorInstance', function(app, selector) {
|
|
const helper = getCodeMirrorInstance(app.__container__);
|
|
return helper(selector);
|
|
});
|
|
}
|