avr39ripe

jsTestingSetup

May 31st, 2021 (edited)
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //package.json
  2.  
  3. {
  4.   "name": "testnode",
  5.   "version": "1.0.0",
  6.   "description": "Testing project for Node.js",
  7.   "main": "index.js",
  8.   "scripts": {
  9.     "test": "node --experimental-vm-modules node_modules/jest/bin/jest.js"
  10.   },
  11.   "author": "avr39-ripe",
  12.   "license": "ISC",
  13.   "devDependencies": {
  14.     "jest": "^27.0.3"
  15.   },
  16.   "jest": {
  17.     "testMatch": [
  18.       "**/__tests__/**/*.?(m|c)js?(x)",
  19.       "**/?(*.)(spec|test).?(m|c)js?(x)"
  20.     ],
  21.     "moduleFileExtensions": [
  22.       "js",
  23.       "cjs",
  24.       "mjs"
  25.     ]
  26.   }
  27.   }
  28.  
  29.  
  30. // end of package.json
  31.  
  32. // functions.mjs
  33. 'use strict'
  34.  
  35. const functions = {
  36.     add: (a,b) => { return a + b;},
  37.     sub: (a,b) => { return a - b +1;}
  38. }
  39.  
  40. export default functions;
  41.  
  42.  
  43. // end of functions.mjs
  44.  
  45. // functions.test.mjs
  46. import functions from './functions.mjs';
  47.  
  48. //console.log(functions.add(2,2));
  49. //console.log(functions.sub(4,2));
  50.  
  51. test('Adds 2 + 2 expext 4', ()=>{
  52.     expect(functions.add(2,2)).toBe(4);
  53. });
  54.  
  55. test('Subtracts 4 - 2 expext 2', ()=>{
  56.     expect(functions.sub(4,2)).toBe(2);
  57. });
  58.  
  59.  
  60. // end of functions.tset.mjs
Add Comment
Please, Sign In to add comment