Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

test each jest

test.each([
  {a: 1, b: 1, expected: 2},
  {a: 1, b: 2, expected: 3},
  {a: 2, b: 1, expected: 3},
])('.add($a, $b)', ({a, b, expected}) => {
  expect(a + b).toBe(expected);
});
Comment

testing jest

const cal = require('../index');

test('adds 1 + 2 to equal 3', () => {
  expect(cal.sum(1, 2)).toBe(3);
  expect(cal.sum(1, 2)).not.toBe(4);
  expect(cal.sum(1, 2)).toBeGreaterThan(2);
  expect(cal.sum(1, 2)).toBeLessThan(4);
  expect(cal.sum(1, 2)).toBeCloseTo(3);
  // Testing datatype
  expect(typeof cal.sum(1, 2)).toBe("number");
});
Comment

testing with jest

npm i jest --save -dev
-> In Package.json change the Script object(watchAll - jest will run auto)
"test" : "jest --watchAll"
-> test file should be named such way that re used by jest can recognize it
like filename.<test> or <spec> or skip it.js
Ex: sum.test.js or sum.spec.js or sum.js
-> require the target for testing file in this test file then enjoy testing.
-> visit jestWebsite-> Docs.
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongoose limit skip 
Javascript :: iconify react 
Javascript :: how to remove last character from string in javascript 
Javascript :: router nodejs 
Javascript :: insertadjacenthtml trong js 
Javascript :: javascript async await not waiting 
Javascript :: google translate javascript 
Javascript :: absolute price in javascript 
Javascript :: jq ridirect 
Javascript :: vue dispatch action at tab close 
Javascript :: TypeError: fxn.call is not a function 
Javascript :: angularjs How to get Capacitor Storage values before doing http call IONIC 6 
Javascript :: javascript alert html 
Javascript :: window.open 
Javascript :: changing photo with js 
Javascript :: how to transform object in string with scaped 
Javascript :: sendmediagroup telegram nodejs 
Javascript :: react native azure 
Javascript :: return jsx in for loop 
Javascript :: formidable node js 
Javascript :: how calculate number of digits of number 
Javascript :: react-native-charts-wrapper:compileDebugJavaWithJavac FAILED 
Javascript :: reverse method in javascript 
Javascript :: intellij debugger export object as json 
Javascript :: how to use aos 
Javascript :: nodejs express routing get 
Javascript :: how to add multiple style attributes in react element 
Javascript :: how to check if element is in viewport javascript 
Javascript :: what is react mounting 
Javascript :: e.target.id not working react js 
ADD CONTENT
Topic
Content
Source link
Name
1+6 =