Skip to content

Commit

Permalink
=> .babelrc: Added babel configuration to allow es2015 syntax for moc…
Browse files Browse the repository at this point in the history
…ha/chai test apis

=> test/index.js: Added test folder and first test draft
=> package.json: Added mocha, chai, babel dependencies
=> package.json: Updated test script
=> .npmignore: Excluded babel configurations for prod release
  • Loading branch information
Ayoub ADIB committed Jul 20, 2016
1 parent ddaf748 commit b3319e2
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions .babelrc
@@ -0,0 +1,5 @@
{
"presets": [
"es2015"
]
}
2 changes: 2 additions & 0 deletions .npmignore
Expand Up @@ -7,3 +7,5 @@ example
.jsbeautifyrc
.tern-project
.eslintrc.json
# .babelrc used for mocha es2015 test (thus for dev not necessary for prod):
.babelrc
8 changes: 6 additions & 2 deletions package.json
Expand Up @@ -7,7 +7,7 @@
"example": "example"
},
"scripts": {
"test": "npm run lint",
"test": "mocha test --compilers js:babel-core/register",
"lint": "eslint src"
},
"repository": {
Expand Down Expand Up @@ -45,9 +45,13 @@
"react-native": ">=0.25.0"
},
"devDependencies": {
"babel-core": "^6.11.4",
"babel-eslint": "^6.1.2",
"babel-preset-es2015": "^6.9.0",
"chai": "^3.5.0",
"eslint": "^3.1.0",
"eslint-plugin-react": "^5.2.2"
"eslint-plugin-react": "^5.2.2",
"mocha": "^2.5.3"
},
"dependencies": {
"babel-plugin-transform-decorators-legacy": "^1.3.4"
Expand Down
41 changes: 41 additions & 0 deletions test/index.js
@@ -0,0 +1,41 @@
//Mocha est le framework de test unitaire le plus célèbre de Nodejs fournissant de nombreux outils et apis
//(cycle de vie des tests, reporting des tests de coverage, reporting concernant la durée des tests, choix libre de la librairie d'assertion...):
//cf. doc apis: https://mochajs.org
//Chai est la librairie, l'outil d'assertion la plus complète (plus complète que le module natif Assert de nodejs (cf. https://nodejs.org/api/assert.html)):
//cf. doc apis: http://chaijs.com/api/
//Mocha et chai peuvent aussi fonctionner côté navigateur: pour initialiser un projet de test côté browser, il suffit de l'initialiser via: mocha init nomProjet

//Bonne documentation unit test dans node.js: http://fredkschott.com/post/2014/05/nodejs-testing-essentials/
//cf. mocha, chai en ES2015: https://onsen.io/blog/mocha-chaijs-unit-test-coverage-es6/

import {
assert
} from "chai";

//L'api mocha "describe"" permet de décrire une suite de test (c'est un container de tests pouvant contenir d'autres describe en son sein):
describe('Array', function() {
//Hooks (api mocha):
before(function() {
// runs before all tests in this block
});

after(function() {
// runs after all tests in this block
});

beforeEach(function() {
// runs before each test in this block
});

afterEach(function() {
// runs after each test in this block
});

//Test cases:
describe('#indexOf()', function() {
//L'api mocha "it" correspond à un jeu de test:
it('should return -1 when the value is not present', function() {
throw new Error("toto");
});
});
});

0 comments on commit b3319e2

Please sign in to comment.