Consistent Testing
electron-settings

Posted by in Software, Tutorial

TL;DR: Delete the settings file before starting the test.

Today I implemented a simple wrapper over the electron-settings functionality to gibe me access to a set of properties via get/set methods. My scenario is simple:

I have a property named path.backup and I want to be able to get, set andtest it’s set`.

The code is:

Now, my testing code would be something along the lines:

And I was surprised to find the test failed in the second part (can detect it has source paths). Consistently.

Then, I was worried the tests would overwrite my own config file (fortunately it doesn’t) and then it hit me: the settings file must be kept between the two tests, including the last value 'one' for the backup path. The fact that I’ve initialised a new Paths() object, it did not help at all! So, my solution is:

Delete the settings file at the beginning of each test:


A little experiment: If you find this post and ad below useful, please check the ad out :-)