File tree Expand file tree Collapse file tree 3 files changed +64
-0
lines changed
js-unit-test-examples/mocha-chai-istanbul Expand file tree Collapse file tree 3 files changed +64
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " js-unit-test-examples-mocha-chai-istanbul" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " index.js" ,
6+ "directories" : {
7+ "test" : " test"
8+ },
9+ "scripts" : {
10+ "test" : " istanbul cover node_modules/mocha/bin/_mocha"
11+ },
12+ "author" : " " ,
13+ "license" : " Unlicense" ,
14+ "devDependencies" : {
15+ "chai" : " ^3.5.0" ,
16+ "istanbul" : " ^0.4.5" ,
17+ "mocha" : " ^3.2.0"
18+ }
19+ }
Original file line number Diff line number Diff line change 1+ module . exports = function ( ) {
2+ this . add = function ( a , b ) {
3+ return a + b ;
4+ } ;
5+
6+ this . multiply = function ( a , b ) {
7+ return a * b ;
8+ } ;
9+
10+ this . fibonacci = function ( length ) {
11+ var sequence = [ 0 , 1 ] ;
12+ for ( var i = 2 ; i <= length ; ++ i ) {
13+ sequence [ i ] = sequence [ i - 1 ] + sequence [ i - 2 ] ;
14+ }
15+ return sequence ;
16+ } ;
17+ } ;
Original file line number Diff line number Diff line change 1+ describe ( 'MathLib' , function ( ) {
2+ var expect = require ( 'chai' ) . expect ;
3+ var MathLib = require ( '../src/index.js' ) ;
4+
5+ describe ( 'add' , function ( ) {
6+ it ( 'adds two numbers together' , function ( ) {
7+ var mathLib = new MathLib ( ) ;
8+ var result = mathLib . add ( 1 , 2 ) ;
9+ expect ( result ) . to . equal ( 3 ) ;
10+ } ) ;
11+ } ) ;
12+
13+ describe ( 'multiply' , function ( ) {
14+ it ( 'multiply two numbers' , function ( ) {
15+ var mathLib = new MathLib ( ) ;
16+ var result = mathLib . multiply ( 3 , 3 ) ;
17+ expect ( result ) . to . equal ( 9 ) ;
18+ } ) ;
19+ } ) ;
20+
21+ describe ( 'fibonacci' , function ( ) {
22+ it ( 'generates a valid fibonacci sequence' , function ( ) {
23+ var mathLib = new MathLib ( ) ;
24+ var result = mathLib . fibonacci ( 12 ) ;
25+ expect ( result [ 12 ] ) . to . equal ( 144 ) ;
26+ } ) ;
27+ } ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments