Unit test - #40
Conversation
…g thanks to unit tests )
jperdereau
left a comment
There was a problem hiding this comment.
Hey @Solinca thx for the contribution
here some small advices
| }, | ||
| "scripts": { | ||
| "test": "NODE_ENV=test mocha './**/*.test.js'", | ||
| "istanbul": "istanbul cover _mocha $(find ./ -name \"*.test.js\" -not -path \"./node_modules/*\")" |
There was a problem hiding this comment.
Usually we are putting all the test files inside a test/ folder
in that case you can simplify the npm scripts:
- mocha should look into the test folder and should be recursive
- istanbul do not have to
findall the test files
There was a problem hiding this comment.
Oh right!
I already put all my tests into an "unit-tests" folder.
My unit test setup file was located on root before I removed it, this is the reason why I wrote those line.
I will apply these changes
| it('add two or more class name', function () { | ||
| const min = 2; | ||
| const max = 5; | ||
| const random = Math.floor(Math.random() * (max - min + 1)) + min; |
There was a problem hiding this comment.
when you do unit testing, usually you avoid randomness for one reason:
if you test failed for a "random" reason if it highly possible that you won't be able to reproduce the issue cause of the randomness of your unit test.
There was a problem hiding this comment.
Yes i'm aware that this test is not 100% trusty because of the randomness.
But when I was writing those tests, I was wondering how could we test a function which have infinite inputs. I made some research about it, and find something called "monkey testing".
It was just an attempt to talk about it ^^
|
|
||
| const addClassNames = require('../src/SwfObjectProcessor/addClassNames'); | ||
| const createSymbols = require('../src/SwfObjectProcessor/createSymbols'); | ||
| const removeSymbols = require('../src/SwfObjectProcessor/removeSymbols'); |
There was a problem hiding this comment.
for clarity, you should have one test file per js file
There was a problem hiding this comment.
Noted, I'll create 3 test files instead of 1 !
|
cc @bchevalier @tbrebant if you have something to add |
Implementation of unit tests ( mocha + chai + istanbul )
Covering 2 files :
SwfObjectProcessor/addClassNames.js
SwfObjectProcessor/createSymbols.js