Mocking config options for Jasmine testing


#1

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)


#2
  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:

https://github.com/lee-dohm/tabs-to-spaces/blob/master/spec/tabs-to-spaces-spec.coffee


#3

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


#4

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?


#5

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.