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 :: copying table element to clipboard using javascript 
Javascript :: mongoose sort 
Javascript :: Add New Properties to a JavaScript Object 
Javascript :: schema mongoose 
Javascript :: readystate==4 
Javascript :: babel compile files empty 
Javascript :: three ways of writing a function in javascript 
Javascript :: gsheet formula get last item in column 
Javascript :: node js hello word 
Javascript :: json schema eg 
Javascript :: Substring in Javascript using slice 
Javascript :: sort array of objects based on another array javascript 
Javascript :: create array in javascript contains 10 elements 
Javascript :: leaflet flyto 
Javascript :: practice javascript 
Javascript :: vue not loading env variables 
Javascript :: like php date("Y-m-d",$value) in javascript 
Javascript :: react hooks in codepen 
Javascript :: how to link prototypes in js using call method 
Javascript :: node import json 
Javascript :: body onload jQuery | jQuery equivalent of body onLoad 
Javascript :: phantomjs in angular 
Javascript :: regular expression javascript 
Javascript :: how to get the value of AutoCompelet Component in MUI 
Javascript :: Image preload React 
Javascript :: js add props to obj conditionally 
Javascript :: Create Your Vue Project 
Javascript :: daysjs 
Javascript :: transition css with js 
Javascript :: string to query string javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+6 =