Editor getGrammar method in test


I’m building a package that’s suppose to work only with certain languages;
in the class constructor (called at activation) I’m checking

Using the binded activation command it works fine, but I’m having problems in testing…

In testing I’m loading a file with an extension that matches a certain grammar, but editor.getGrammar().scopeName returns text.plain.null-grammar

openfile = atom.workspace.open(filepath).then((e) => {
  editor = e;
  console.log('editor', e)
  console.log('editor.getGrammar',editor.getGrammar()); // NullGrammar

I can tell from the buffer the editor is the correct one, why am I getting nullGrammar ?


Have you activated the grammar package for the language you want to Atom to detect? In tests, Atom doesn’t activate any packages by default. If you want them to be present in your tests, you have to activate them yourself.


added atom.packages.activatePackage('language-javascript') and now works like a charm,