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 :: jquery remove all alerts 
Javascript :: v-show example in vue js 
Javascript :: devtool google 
Javascript :: invisible recaptcha google 
Javascript :: read string using stream nodejs 
Javascript :: javascript bind multiple arguments 
Javascript :: Discord.js v13 / command handler 
Javascript :: map react 
Javascript :: add class to new element javascript 
Javascript :: startswith in javascript 
Javascript :: js foreach mdn 
Javascript :: how to print json.stringify of nested objects 
Javascript :: js list random order 
Javascript :: what is next.js 
Javascript :: ngShow 
Javascript :: javascript number and math 
Javascript :: js some 
Javascript :: nodemailer 
Javascript :: node.js generate certificate 
Javascript :: knex pagination plugin 
Javascript :: angular.json 
Javascript :: change parent state from child use effect in react js 
Javascript :: use promise in angular 8 
Javascript :: bind() method 
Javascript :: nested callbacks javascript 
Javascript :: js standard global 
Javascript :: .classList 
Javascript :: js try without catch 
Javascript :: alert in react native 
Javascript :: jquerey dropdown button 
ADD CONTENT
Topic
Content
Source link
Name
8+2 =