Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ADD: Testing documentation #513

Merged
merged 1 commit into from
Jan 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,10 @@ $ grunt concat:dist

3. _Optional_: We use SVG for our icon system. Please visit our wiki [SVG Icon System](https://github.com/publiclab/Leaflet.DistortableImage/wiki/SVG-Icon-System) if you are interested in making updates to them or just simply learning about our workflow.

### Testing

[Guide](TESTING.md) on testing LDI.

---

### Contributors
Expand Down
71 changes: 71 additions & 0 deletions TESTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
## Testing

We use Mocha & Karma with the help of Grunt for testing.

To learn more about these tools, visit the official docs:

- [Mocha](https://mochajs.org/#getting-started)
- [Karma](https://karma-runner.github.io/4.0/config/configuration-file.html)
- [Grunt](https://gruntjs.com/getting-started)

`npm test` runs tests from the `test/` folder.



`npm test` is just a wrapper around `grunt test` task which runs JSHint and Karma tasks.

[JSHint](https://jshint.com/docs/) is a JavaScript code quality tool, an alternative to [ESLint](https://eslint.org/).

[Karma](https://karma-runner.github.io/latest/index.html) is a test runner, it allows us to test our code in multiple browsers and devices.



### Running just one test

For this, you need to install Mocha globally. Run `npm i -g mocha`

After you've successfully installed Mocha, you can run just one type of test by passing a test file to Mocha:

`mocha <filename>.js`



### Running a single test block within a test file

In order to do this, you don't need to install Mocha globally.

You can just attach a `.only()` function call to a test block that you want to execute.

It can be attached to both, `describe` and `it` test blocks.



**EXAMPLE**:

```javascript
it('tests feature 1', function(){
// I won't run :(
});

it.only('tests feature 2', function(){
// I'll run :)
});

it('tests feature 3', function(){
// I won't run :(
});
```



### Skipping tests

Sometimes, we just want to write a boilerplate code for a test, but we don't want to implement it yet.

We can attach `.skip()` function call, which will skip our `it` or `describe` blocks, works just like `.only()`.



**NOTE**: After you finish writing a test, remember to remove your `.only()`or `.skip()` calls.

They are meant for development purposes, in the production we don't want to alter the actual code of our tests.