Mocking config options for Jasmine testing


I’m trying to test a class that uses atom.config.get(‘package.variable’) but it seems as though during testing this method returns undefined, which I guess makes sense. Is there a way to mock this behavior? (without having to refactor my code to pass a spy into the constructor)

  1. Are you setting a value for it to read? (I’m pretty sure the Atom Jasmine stuff loads a blank config to prevent your personal settings from polluting the results of the test.)
  2. Are you activating your package first?

Take a look at the specs in my tabs-to-spaces package where I use configuration fairly extensively:


Ah that fixed it! Forgot to set it beforehand, thank you.


I have never seen this construct before. Is it any different than buffer = directory = editor = filePath = workspaceElement = null which would be a bit less obscure?


In effect, it does the same thing, yes. It generates different JavaScript code … but doubtful that it makes any difference at all. The construct can be found in at least some of the Atom package specs, which is where I picked it up from.