File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed
js-unit-test-examples/mocha-chai-ts-istanbul Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " js-unit-test-examples-mocha-chai-ts-istanbul" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " index.js" ,
6+ "directories" : {
7+ "test" : " test"
8+ },
9+ "scripts" : {
10+ "test" : " ts-node node_modules/istanbul/lib/cli.js cover -e .ts node_modules/mocha/bin/_mocha -- test/**/*.test.ts"
11+ },
12+ "author" : " " ,
13+ "license" : " Unlicense" ,
14+ "devDependencies" : {
15+ "@types/mocha" : " ^2.2.38" ,
16+ "@types/node" : " ^7.0.4" ,
17+ "chai" : " ^3.5.0" ,
18+ "istanbul" : " ^1.1.0-alpha.1" ,
19+ "mocha" : " ^3.2.0" ,
20+ "ts-node" : " ^2.0.0" ,
21+ "typescript" : " ^2.1.5"
22+ }
23+ }
Original file line number Diff line number Diff line change 1+ export class MathLib {
2+ add ( a , b ) : Number {
3+ return a + b ;
4+ }
5+
6+ multiply ( a , b ) : Number {
7+ return a * b ;
8+ }
9+
10+ fibonacci ( length ) : Number [ ] {
11+ const sequence = [ 0 , 1 ] ;
12+ for ( let 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+ /// <reference path="../node_modules/@types/node/index.d.ts" />
2+ /// <reference path="../node_modules/@types/mocha/index.d.ts" />
3+
4+ import { expect } from 'chai' ;
5+ import { MathLib } from '../src' ;
6+
7+ describe ( 'MathLib' , ( ) => {
8+ describe ( 'add' , ( ) => {
9+ it ( 'adds two numbers together' , ( ) => {
10+ const mathLib = new MathLib ( ) ;
11+ const result = mathLib . add ( 1 , 2 ) ;
12+ expect ( result ) . to . equal ( 3 ) ;
13+ } ) ;
14+ } ) ;
15+
16+ describe ( 'multiply' , ( ) => {
17+ it ( 'multiply two numbers' , ( ) => {
18+ const mathLib = new MathLib ( ) ;
19+ const result = mathLib . multiply ( 3 , 3 ) ;
20+ expect ( result ) . to . equal ( 9 ) ;
21+ } ) ;
22+ } ) ;
23+
24+ describe ( 'fibonacci' , ( ) => {
25+ it ( 'generates a valid fibonacci sequence' , ( ) => {
26+ const mathLib = new MathLib ( ) ;
27+ const result = mathLib . fibonacci ( 12 ) ;
28+ expect ( result [ 12 ] ) . to . equal ( 144 ) ;
29+ } ) ;
30+ } ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments