Create tests for hasStore()
See original GitHub issueMission Control
The DAV project you are looking at is Mission Control. It is the brain in charge of orchestrating missions between DAV users and autonomous vehicles.
How you can help
The Issue
As a project that relies on a large community of contributors, it is very important for us to have good test coverage to make sure changes don’t break anything.
The file /server/lib/environment.js
isn’t tested at all. Create a file /test/specs/lib.environment.spec.js
that will test the function hasStore()
Test that hasStore()
fulfills these conditions:
- returns false if the DAV_ENV environment variable isn’t set to ‘simulated’
You might want to write the test so that it tests both conditions. You can get the environment variable in node using: process.env.DAV_ENV
You can see how this file should be structured based on the other files in the specs directory.
To run your tests, run npm test
from the project’s root directory. All tests should pass.
Contributing to Mission Control
- Fork the repository from the Mission Control GitHub page.
- Clone a copy to your local machine with
$ git clone git@github.com:YOUR-GITHUB-USER-NAME/missioncontrol.git
- Make sure you have node.js and npm installed on your machine. You can use this guide for help.
- Install all of the project’s dependencies with npm.
$ cd missioncontrol; npm install
- Run
npm test
to run linting checks and all the automated tests and see that they pass. - Code! code! code!
- Before committing your code, run
npm test
one last time and make sure no errors (including linting errors) are thrown. - Once you’ve made sure all your changes work correctly and committed all your changes, push your local changes back to github with
$ git push -u origin master
- Visit your fork on GitHub.com (https://github.com/YOUR-USER-NAME/missioncontrol) and create a pull request for your changes.
- Make sure your pull request describes exactly what you changed and references this issue (include the issue number in the title like this:
#28
)
Issue Analytics
- State:
- Created 6 years ago
- Comments:10 (10 by maintainers)
Top GitHub Comments
First, a quick note. Since we want to make sure it returns false, I would use
toBe(false)
rather thantoBeFalsy()
. The latter would also work if it returns 0, ‘’, null, undefined, or NaN. See https://facebook.github.io/jest/docs/en/expect.html#tobefalsySecond, we want to have each of our tests self-contained and just test a single condition. In other words, the tests that asserts that it
returns false if the DAV_ENV environment variable isn't set to 'simulated'
, should not also test what happens when the environment is set tosimulated
(so, noelse
).Now, regarding the test itself. It’s actually an interesting question of what to test here.
One obvious solution might be to
expect(env !== 'simulation' && hasStore === false)
(that’s pseudocode). But it feels to me like a more correct solution would be not to test for the environment variable as part of the assertion, and just test the thing we are testing.In other words, I think this would be more correct:
It’s a subtle difference but it seems like a more correct one. The assertion just tests what we came here to test… and if in the future we change the environment that tests run in, it shouldn’t fail on
returns false when the DAV_ENV environment variable isn't set to 'simulated'
becausehasStore
didn’t break - it functioned correctly, it was the test that failed.What would happen is that we would get an error saying
Expected one assertion to be called but only received zero assertion calls.
This would be a good chance for us to add tests for other environments.This would also leave it up to us to implement a future test for the environment separately, and not tied into the test for hasStore.
This is just my view of the matter. You can expect
myView.toBeTruthy()
, but not necessarilymyView.toBe(the only truth)
😉P.S. I made a mistake in the task description.
hasStore
is not actually a function but a constant value. so there’s no need to invoke it. Leave the description of the test as is, as I will be refactoring it to a function once you are done adding the test.Looks great, @Rob-Rychs!
Thank you, and thank you for bearing with my idiosyncrasies 😄
Congrats on joining the community, and becoming an open-sourcerer!