File tree Expand file tree Collapse file tree 3 files changed +62
-0
lines changed
js-unit-test-examples/jest Expand file tree Collapse file tree 3 files changed +62
-0
lines changed Original file line number Diff line number Diff line change 1+ {
2+ "name" : " js-unit-test-examples-jest" ,
3+ "version" : " 1.0.0" ,
4+ "description" : " " ,
5+ "main" : " index.js" ,
6+ "scripts" : {
7+ "test" : " jest"
8+ },
9+ "author" : " " ,
10+ "license" : " Unlicense" ,
11+ "devDependencies" : {
12+ "jest" : " ^18.1.0"
13+ },
14+ "jest" : {
15+ "collectCoverage" : true ,
16+ "collectCoverageFrom" : [" src/**/*.js" ]
17+ }
18+ }
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+ const MathLib = require ( '../src' ) ;
2+
3+ describe ( 'MathLib' , ( ) => {
4+ describe ( 'add' , ( ) => {
5+ it ( 'adds two numbers together' , ( ) => {
6+ const mathLib = new MathLib ( ) ;
7+ const result = mathLib . add ( 1 , 2 ) ;
8+ expect ( result ) . toBe ( 3 ) ;
9+ } ) ;
10+ } ) ;
11+
12+ describe ( 'multiply' , ( ) => {
13+ it ( 'multiply two numbers' , ( ) => {
14+ const mathLib = new MathLib ( ) ;
15+ const result = mathLib . multiply ( 3 , 3 ) ;
16+ expect ( result ) . toBe ( 9 ) ;
17+ } ) ;
18+ } ) ;
19+
20+ describe ( 'fibonacci' , ( ) => {
21+ it ( 'generates a valid fibonacci sequence' , ( ) => {
22+ const mathLib = new MathLib ( ) ;
23+ const result = mathLib . fibonacci ( 12 ) ;
24+ expect ( result [ 12 ] ) . toBe ( 144 ) ;
25+ } ) ;
26+ } ) ;
27+ } ) ;
You can’t perform that action at this time.
0 commit comments