github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/ui/tests/helpers/codemirror.js (about)

     1  const invariant = (truthy, error) => {
     2    if (!truthy) throw new Error(error);
     3  };
     4  
     5  export function getCodeMirrorInstance(container) {
     6    return function(selector) {
     7      const cmService = container.lookup('service:code-mirror');
     8  
     9      const element = document.querySelector(selector);
    10      invariant(element, `Selector ${selector} matched no elements`);
    11  
    12      const cm = cmService.instanceFor(element.id);
    13      invariant(cm, `No registered CodeMirror instance for ${selector}`);
    14  
    15      return cm;
    16    };
    17  }
    18  
    19  export default function setupCodeMirror(hooks) {
    20    hooks.beforeEach(function() {
    21      this.getCodeMirrorInstance = getCodeMirrorInstance(this.owner);
    22  
    23      // Expose to window for access from page objects
    24      window.getCodeMirrorInstance = this.getCodeMirrorInstance;
    25    });
    26  
    27    hooks.afterEach(function() {
    28      delete window.getCodeMirrorInstance;
    29      delete this.getCodeMirrorInstance;
    30    });
    31  }