{"id":112326,"date":"2021-12-18T15:15:00","date_gmt":"2021-12-18T13:15:00","guid":{"rendered":"https:\/\/www.javacodegeeks.com\/?p=112326"},"modified":"2021-12-09T14:34:58","modified_gmt":"2021-12-09T12:34:58","slug":"parameterized-tests-in-javascript-with-jest","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html","title":{"rendered":"Parameterized tests in JavaScript with Jest"},"content":{"rendered":"<p><em>Parameterized<\/em> tests are used to test the same code under different conditions. One can set up a test method that retrieves data from a data source. This data source can be a collection of objects, external file or maybe even a database. The general idea is to make it easy to test different conditions with the same test method to avoid duplication and make the code easier to read and maintain.<\/p>\n<p><code>Jest<\/code> has a built-in support for tests parameterized with data table that can be provided either by an <em>array of arrays<\/em> or as <em>tagged template literal<\/em>.<a name=\"more\"><\/a><\/p>\n<h2 class=\"wp-block-heading\">The code<\/h2>\n<p>Let\u2019s consider a simple <code>Calculator<\/code> fn that accepts an operator and the numbers array:<\/p>\n<pre class=\"wp-block-preformatted brush:c\">type Operator = '+' | '-' | '*' | '\/';\n\nexport default function calculator(operator: Operator, inputs: number[]) {\n\n    if (inputs.length &lt; 2) {\n        throw new Error(`inputs should have length &gt;= 2`);\n    }\n\n    switch (operator) {\n        case '+':\n            return inputs.reduce((prev, curr) =&gt; prev + curr);\n        case '-':\n            return inputs.reduce((prev, curr) =&gt; prev - curr);\n        case '*':\n            return inputs.reduce((prev, curr) =&gt; prev * curr);\n        case '\/':\n            return inputs.reduce((prev, curr) =&gt; prev \/ curr);\n        default:\n            throw new Error(`Unknown operator ${operator}`);\n    }\n}<\/pre>\n<p>The <code>Calculator<\/code> can be tested using the following scenarios:<\/p>\n<pre class=\"wp-block-preformatted brush:c\">import calculator from '.\/calculator';\n\ndescribe('Calculator', () =&gt; {\n    it('throws error when input.length &lt; 2', () =&gt; {\n        expect(() =&gt; calculator('+', [0])).toThrow('inputs should have length &gt;= 2');\n    });\n\n    it('throws error when unsupported operator was used', () =&gt; {\n        \/\/ eslint-disable-next-line @typescript-eslint\/ban-ts-comment\n        \/\/ @ts-ignore\n        expect(() =&gt; calculator('&amp;', [0, 0])).toThrow('unknown operator &amp;');\n    });\n\n    it('adds 2 or more numbers incl. `NaN` and `Infinity`', () =&gt; {\n        expect(calculator('+', [1, 41])).toEqual(42);\n        expect(calculator('+', [1, 2, 39])).toEqual(42);\n        expect(calculator('+', [1, 2, NaN])).toEqual(NaN);\n        expect(calculator('+', [1, 2, Infinity])).toEqual(Infinity);\n    });\n\n    it('subtracts 2 or more numbers incl. `NaN` and `Infinity`', () =&gt; {\n        expect(calculator('-', [43, 1])).toEqual(42);\n        expect(calculator('-', [44, 1, 1])).toEqual(42);\n        expect(calculator('-', [1, 2, NaN])).toEqual(NaN);\n        expect(calculator('-', [1, 2, Infinity])).toEqual(-Infinity);\n    });\n\n    it('multiplies 2 or more numbers incl. `NaN` and `Infinity`', () =&gt; {\n        expect(calculator('*', [21, 2])).toEqual(42);\n        expect(calculator('*', [3, 7, 2])).toEqual(42);\n        expect(calculator('*', [42, NaN])).toEqual(NaN);\n        expect(calculator('*', [42, Infinity])).toEqual(Infinity);\n    });\n\n    it('divides 2 or more numbers incl. `NaN` and `Infinity`', () =&gt; {\n        expect(calculator('\/', [84, 2])).toEqual(42);\n        expect(calculator('\/', [42, 0])).toEqual(Infinity);\n        expect(calculator('\/', [42, NaN])).toEqual(NaN);\n        expect(calculator('\/', [168, 2, 2])).toEqual(42);\n    });\n});<\/pre>\n<p>The most important scenarios are focused on the <code>Calculator<\/code> main features (<em>add<\/em>, <em>subtract<\/em>, <em>multiple<\/em> and <em>divide<\/em>) and each of the features is tested with differect set of data values. These tests could be <em>parameterized<\/em> as they are duplicating the same test logic with different data.<\/p>\n<h2 class=\"wp-block-heading\">Parameterized (<em>data-driven<\/em>) tests in <code>jest<\/code><\/h2>\n<p>In <code>Jest<\/code>, paramaterized tests can be created with <code>.each<\/code> that come with the APIs: <code>.each(table)(name, fn)<\/code> and <code>.each`table`(name, fn)<\/code> where the difference is how the test data is provided.<\/p>\n<h2 class=\"wp-block-heading\"><code>test.each(table)(name, fn)<\/code><\/h2>\n<p>In this example, data is provided as an <em>array of arrays<\/em> with the arguments that are injected into the test function for each row. Unique test names are created by positioinally injecting parameters:<\/p>\n<pre class=\"wp-block-preformatted brush:c\">import calculator from '.\/calculator';\n\ndescribe('Calculator', () =&gt; {\n    it.each([\n        [[1, 41], 42],\n        [[1, 2, 39], 42],\n        [[1, 2, NaN], NaN],\n        [[1, 2, Infinity], Infinity],\n    ])('adds %p expecting %p', (numbers: number[], result: number) =&gt; {\n        expect(calculator('+', numbers)).toEqual(result);\n    });\n\n    it.each([\n        [[43, 1], 42],\n        [[44, 1, 1], 42],\n        [[1, 2, NaN], NaN],\n        [[1, 2, Infinity], -Infinity],\n    ])('subtracts %p expecting %p', (numbers: number[], result: number) =&gt; {\n        expect(calculator('-', numbers)).toEqual(result);\n    });\n\n    it.each([\n        [[21, 2], 42],\n        [[3, 7, 2], 42],\n        [[42, NaN], NaN],\n        [[42, Infinity], Infinity],\n    ])('multiplies %p expecting %p', (numbers: number[], result: number) =&gt; {\n        expect(calculator('*', numbers)).toEqual(result);\n    });\n\n    it.each([\n        [[84, 2], 42],\n        [[168, 2, 2], 42],\n        [[168, 2, 2], 42],\n        [[42, 0], Infinity],\n        [[42, NaN], NaN],\n    ])('divides %p expecting %p', (numbers: number[], result: number) =&gt; {\n        expect(calculator('\/', numbers)).toEqual(result);\n    });\n});<\/pre>\n<p>Please note that in a <em>parameterized<\/em> test, each data table row creates a new test that has exactly the same lifecylce as the regular test created with the test clousure. For this example, there are <strong>16<\/strong> tests (<strong>4<\/strong> tests and <em>each<\/em> with <strong>4<\/strong> sets of data values):<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"wp-block-preformatted brush:java\">PASS  src\/parameterized\/calculatorParameterized1.test.ts\n  Calculator\n    \u2713 adds [1, 41] expecting 42 (2 ms)\n    \u2713 adds [1, 2, 39] expecting 42\n    \u2713 adds [1, 2, NaN] expecting NaN\n    \u2713 adds [1, 2, Infinity] expecting Infinity\n    \u2713 subtracts [43, 1] expecting 42\n    \u2713 subtracts [44, 1, 1] expecting 42\n    \u2713 subtracts [1, 2, NaN] expecting NaN\n    \u2713 subtracts [1, 2, Infinity] expecting -Infinity\n    \u2713 multiplies [21, 2] expecting 42 (1 ms)\n    \u2713 multiplies [3, 7, 2] expecting 42 (1 ms)\n    \u2713 multiplies [42, NaN] expecting NaN\n    \u2713 multiplies [42, Infinity] expecting Infinity (1 ms)\n    \u2713 divides [84, 2] expecting 42\n    \u2713 divides [168, 2, 2] expecting 42\n    \u2713 divides [168, 2, 2] expecting 42\n    \u2713 divides [42, 0] expecting Infinity\n    \u2713 divides [42, NaN] expecting NaN (1 ms)\n\nTest Suites: 1 passed, 1 total\nTests:       17 passed, 17 total\nSnapshots:   0 total\nTime:        2.361 s, estimated 3 s\nRan all test suites matching \/src\\\/parameterized\\\/calculatorParameterized1.test.ts\/i.\n\u2728  Done in 3.55s.<\/pre>\n<p>In case of a failure you may expect only failed tests are reported, like in the example below:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">FAIL  src\/parameterized\/calculatorParameterized1.test.ts\n  Calculator\n    \u2713 adds [1, 41] expecting 42 (1 ms)\n    \u2713 adds [1, 2, 39] expecting 42 (3 ms)\n    \u2715 adds [1, 2, NaN] expecting Infinity (1 ms)\n    \u2713 adds [1, 2, Infinity] expecting Infinity\n    \u2713 subtracts [43, 1] expecting 42 (1 ms)\n    \u2713 subtracts [44, 1, 1] expecting 42\n    \u2713 subtracts [1, 2, NaN] expecting NaN (1 ms)\n    \u2713 subtracts [1, 2, Infinity] expecting -Infinity\n    \u2713 multiplies [21, 2] expecting 42\n    \u2713 multiplies [3, 7, 2] expecting 42\n    \u2713 multiplies [42, NaN] expecting NaN\n    \u2713 multiplies [42, Infinity] expecting Infinity\n    \u2713 divides [84, 2] expecting 42 (1 ms)\n    \u2713 divides [168, 2, 2] expecting 42\n    \u2713 divides [168, 2, 2] expecting 42\n    \u2713 divides [42, 0] expecting Infinity\n    \u2715 divides [42, NaN] expecting Infinity (1 ms)\n\n  \u25cf Calculator \u203a adds [1, 2, NaN] expecting Infinity\n\n    expect(received).toEqual(expected) \/\/ deep equality\n\n    Expected: Infinity\n    Received: NaN\n\n       8 |         [[1, 2, Infinity], Infinity],\n       9 |     ])('adds %p expecting %p', (numbers: number[], result: number) =&gt; {\n    &gt; 10 |         expect(calculator('+', numbers)).toEqual(result);\n         |                                          ^\n      11 |     });\n      12 |\n      13 |     it.each([\n\n      at src\/parameterized\/calculatorParameterized1.test.ts:10:42\n\n  \u25cf Calculator \u203a divides [42, NaN] expecting Infinity\n\n    expect(received).toEqual(expected) \/\/ deep equality\n\n    Expected: Infinity\n    Received: NaN\n\n      36 |         [[42, NaN], Infinity],\n      37 |     ])('divides %p expecting %p', (numbers: number[], result: number) =&gt; {\n    &gt; 38 |         expect(calculator('\/', numbers)).toEqual(result);\n         |                                          ^\n      39 |     });\n      40 | });\n      41 |\n\n      at src\/parameterized\/calculatorParameterized1.test.ts:38:42\n\nTest Suites: 1 failed, 1 total\nTests:       2 failed, 15 passed, 17 total\nSnapshots:   0 total\nTime:        2.493 s, estimated 3 s<\/pre>\n<h2 class=\"wp-block-heading\"><code>test.each`table`(name, fn)<\/code><\/h2>\n<p>In this example, data is provided with <em>template literal<\/em>, where the first row represents name of variables and the subsequent rows provide test data object injected into the test function for each row. The unique test names are created by injecting parameters by their name.<\/p>\n<pre class=\"wp-block-preformatted brush:c\">import calculator from '.\/calculator';\n\ndescribe('Calculator', () =&gt; {\n    it.each`\n    numbers             | result\n    ${[1, 41]}          | ${42} \n    ${[1, 2, 39]}       | ${42} \n    ${[1, 2, NaN]}      | ${NaN} \n    ${[1, 2, Infinity]} | ${Infinity}  \n    `('adds $numbers expecting $result', ({ numbers, result }) =&gt; {\n        expect(calculator('+', numbers)).toEqual(result);\n    });\n\n    it.each`\n    numbers             | result\n    ${[43, 1]}          | ${42} \n    ${[44, 1, 1]}       | ${42}\n    ${[1, 2, NaN]}      | ${NaN} \n    ${[1, 2, Infinity]} | ${-Infinity} \n    `('subtracts $numbers expecting $result', ({ numbers, result }) =&gt; {\n        expect(calculator('-', numbers)).toEqual(result);\n    });\n\n    it.each`\n    numbers           | result\n    ${[21, 2]}        | ${42} \n    ${[3, 7, 2]}      | ${42} \n    ${[42, NaN]}      | ${NaN}  \n    ${[42, Infinity]} | ${Infinity}  \n    `('multiples $numbers expecting $result', ({ numbers, result }) =&gt; {\n        expect(calculator('*', numbers)).toEqual(result);\n    });\n\n    it.each`\n    numbers        | result\n    ${[84, 2]}     | ${42} \n    ${[168, 2, 2]} | ${42} \n    ${[42, 0]}     | ${Infinity}  \n    ${[42, NaN]}   | ${NaN}  \n    `('divides $numbers expecting $result', ({ numbers, result }) =&gt; {\n        expect(calculator('\/', numbers)).toEqual(result);\n    });\n});<\/pre>\n<p>In this example, also <strong>16<\/strong> tests were created:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">PASS  src\/parameterized\/calculatorParameterized2.test.ts\n  Calculator\n    \u2713 adds [1, 41] expecting 42 (1 ms)\n    \u2713 adds [1, 2, 39] expecting 42\n    \u2713 adds [1, 2, NaN] expecting NaN (1 ms)\n    \u2713 adds [1, 2, Infinity] expecting Infinity\n    \u2713 subtracts [43, 1] expecting 42 (1 ms)\n    \u2713 subtracts [44, 1, 1] expecting 42\n    \u2713 subtracts [1, 2, NaN] expecting NaN\n    \u2713 subtracts [1, 2, Infinity] expecting -Infinity\n    \u2713 multiples [21, 2] expecting 42\n    \u2713 multiples [3, 7, 2] expecting 42 (1 ms)\n    \u2713 multiples [42, NaN] expecting NaN (1 ms)\n    \u2713 multiples [42, Infinity] expecting Infinity\n    \u2713 divides [84, 2] expecting 42 (1 ms)\n    \u2713 divides [168, 2, 2] expecting 42\n    \u2713 divides [42, 0] expecting Infinity\n    \u2713 divides [42, NaN] expecting NaN\n\nTest Suites: 1 passed, 1 total\nTests:       16 passed, 16 total\nSnapshots:   0 total\nTime:        2.432 s, estimated 3 s\nRan all test suites matching \/src\\\/parameterized\\\/calculatorParameterized2.test.ts\/i.\n\u2728  Done in 3.36s.<\/pre>\n<h2 class=\"wp-block-heading\">Ultimate parameterized test for the <code>Calculator<\/code><\/h2>\n<p>The previous example could be further improved by adding an additional test param: <code>operator<\/code> which in the end reduces the code repeatition:<\/p>\n<pre class=\"wp-block-preformatted brush:c\">import calculator from '.\/calculator';\n\ndescribe('Calculator', () =&gt; {\n    it.each`\n    numbers             | operator | result\n    ${[1, 41]}          | ${\"+\"}   | ${42} \n    ${[1, 2, 39]}       | ${\"+\"}   | ${42} \n    ${[1, 2, NaN]}      | ${\"+\"}   | ${NaN} \n    ${[1, 2, Infinity]} | ${\"+\"}   | ${Infinity}  \n    ${[43, 1]}          | ${\"-\"}   | ${42} \n    ${[44, 1, 1]}       | ${\"-\"}   | ${42}\n    ${[1, 2, NaN]}      | ${\"-\"}   | ${NaN} \n    ${[1, 2, Infinity]} | ${\"-\"}   | ${-Infinity} \n    ${[21, 2]}          | ${\"*\"}   | ${42} \n    ${[3, 7, 2]}        | ${\"*\"}   | ${42} \n    ${[42, NaN]}        | ${\"*\"}   | ${NaN}  \n    ${[42, Infinity]}   | ${\"*\"}   | ${Infinity}\n    ${[84, 2]}          | ${\"\/\"}   | ${42} \n    ${[168, 2, 2]}      | ${\"\/\"}   | ${42} \n    ${[42, 0]}          | ${\"\/\"}   | ${Infinity}  \n    ${[42, NaN]}        | ${\"\/\"}   | ${NaN}    \n    `('verifies \"$operator\" on $numbers expecting $result', ({ numbers, operator, result }) =&gt; {\n        expect(calculator(operator, numbers)).toEqual(result);\n    });\n});<\/pre>\n<p>And the test run:<\/p>\n<pre class=\"wp-block-preformatted brush:java\">PASS  src\/parameterized\/calculatorParameterized3.test.ts\n  Calculator\n    \u2713 verifies \"+\" on [1, 41] expecting 42\n    \u2713 verifies \"+\" on [1, 2, 39] expecting 42\n    \u2713 verifies \"+\" on [1, 2, NaN] expecting NaN\n    \u2713 verifies \"+\" on [1, 2, Infinity] expecting Infinity\n    \u2713 verifies \"-\" on [43, 1] expecting 42\n    \u2713 verifies \"-\" on [44, 1, 1] expecting 42\n    \u2713 verifies \"-\" on [1, 2, NaN] expecting NaN\n    \u2713 verifies \"-\" on [1, 2, Infinity] expecting -Infinity\n    \u2713 verifies \"*\" on [21, 2] expecting 42\n    \u2713 verifies \"*\" on [3, 7, 2] expecting 42\n    \u2713 verifies \"*\" on [42, NaN] expecting NaN\n    \u2713 verifies \"*\" on [42, Infinity] expecting Infinity\n    \u2713 verifies \"\/\" on [84, 2] expecting 42\n    \u2713 verifies \"\/\" on [168, 2, 2] expecting 42\n    \u2713 verifies \"\/\" on [42, 0] expecting Infinity\n    \u2713 verifies \"\/\" on [42, NaN] expecting NaN\n\nTest Suites: 1 passed, 1 total\nTests:       16 passed, 16 total\nSnapshots:   0 total\nTime:        2.463 s, estimated 3 s\n\u2728  Done in 3.66s.<\/pre>\n<h2 class=\"wp-block-heading\">In review<\/h2>\n<ul class=\"wp-block-list\">\n<li>Use <em>parameterized<\/em> tests when you duplicate test logic for different test data.<\/li>\n<li>Don\u2019t overuse <em>parameterized<\/em> tests especially in slower ones like <em>integration<\/em> or <em>e2e<\/em>.<\/li>\n<li>Generate unique test names for better error messages and easier debugging of failed tests.<\/li>\n<li>Remember, that each data row creates a new test with a default test lifecycle.<\/li>\n<\/ul>\n<h2 class=\"wp-block-heading\">See also<\/h2>\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/jestjs.io\/docs\/api#testeachtablename-fn-timeout\">Learn more about the <code>.each<\/code> APIs in the official documentation<\/a><\/li>\n<li><a href=\"https:\/\/blog.codeleak.pl\/2021\/11\/testing-exceptions-in-javascript.html\">Testing exceptions in JavaScript with Jest<\/a><\/li>\n<li><a href=\"https:\/\/blog.codeleak.pl\/2021\/11\/testing-promise-rejection-with-jest.html\">Testing promise rejection in JavaScript with Jest<\/a><\/li>\n<\/ul>\n<div class=\"attribution\">\n<table>\n<tbody>\n<tr>\n<td>\n<p>Published on Java Code Geeks with permission by Rafal Borowiec, partner at our <a href=\"\/\/www.javacodegeeks.com\/join-us\/jcg\/\" target=\"_blank\" rel=\"noopener\">JCG program<\/a>. See the original article here: <a href=\"https:\/\/blog.codeleak.pl\/2021\/12\/parameterized-tests-with-jest.html\" target=\"_blank\" rel=\"noopener\">Parameterized tests in JavaScript with Jest<\/a><\/p>\n<p>Opinions expressed by Java Code Geeks contributors are their own.<\/p>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Parameterized tests are used to test the same code under different conditions. One can set up a test method that retrieves data from a data source. This data source can be a collection of objects, external file or maybe even a database. The general idea is to make it easy to test different conditions with &hellip;<\/p>\n","protected":false},"author":516,"featured_media":20900,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1879],"tags":[2066,1774],"class_list":["post-112326","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-javascript","tag-jest","tag-unit-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Parameterized tests in JavaScript with Jest - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn about Parameterized tests? Check our article explaining parameterized tests in JavaScript with Jest.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Parameterized tests in JavaScript with Jest - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn about Parameterized tests? Check our article explaining parameterized tests in JavaScript with Jest.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2021-12-18T13:15:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Rafal Borowiec\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/kolorobot\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rafal Borowiec\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"9 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html\"},\"author\":{\"name\":\"Rafal Borowiec\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/b1a0b2657d5dd2459806446ac66d2d52\"},\"headline\":\"Parameterized tests in JavaScript with Jest\",\"datePublished\":\"2021-12-18T13:15:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html\"},\"wordCount\":490,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"keywords\":[\"jest\",\"Unit Testing\"],\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html\",\"name\":\"Parameterized tests in JavaScript with Jest - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"datePublished\":\"2021-12-18T13:15:00+00:00\",\"description\":\"Interested to learn about Parameterized tests? Check our article explaining parameterized tests in JavaScript with Jest.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2014\\\/01\\\/javascript-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2021\\\/12\\\/parameterized-tests-in-javascript-with-jest.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Web Development\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/web-development\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Parameterized tests in JavaScript with Jest\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/b1a0b2657d5dd2459806446ac66d2d52\",\"name\":\"Rafal Borowiec\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g\",\"caption\":\"Rafal Borowiec\"},\"description\":\"Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.\",\"sameAs\":[\"http:\\\/\\\/blog.codeleak.pl\\\/\",\"http:\\\/\\\/pl.linkedin.com\\\/in\\\/borowiec\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/kolorobot\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/rafal-borowiec\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Parameterized tests in JavaScript with Jest - Java Code Geeks","description":"Interested to learn about Parameterized tests? Check our article explaining parameterized tests in JavaScript with Jest.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html","og_locale":"en_US","og_type":"article","og_title":"Parameterized tests in JavaScript with Jest - Java Code Geeks","og_description":"Interested to learn about Parameterized tests? Check our article explaining parameterized tests in JavaScript with Jest.","og_url":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2021-12-18T13:15:00+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","type":"image\/jpeg"}],"author":"Rafal Borowiec","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/kolorobot","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Rafal Borowiec","Est. reading time":"9 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html"},"author":{"name":"Rafal Borowiec","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/b1a0b2657d5dd2459806446ac66d2d52"},"headline":"Parameterized tests in JavaScript with Jest","datePublished":"2021-12-18T13:15:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html"},"wordCount":490,"commentCount":1,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","keywords":["jest","Unit Testing"],"articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html","url":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html","name":"Parameterized tests in JavaScript with Jest - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","datePublished":"2021-12-18T13:15:00+00:00","description":"Interested to learn about Parameterized tests? Check our article explaining parameterized tests in JavaScript with Jest.","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2014\/01\/javascript-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2021\/12\/parameterized-tests-in-javascript-with-jest.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Web Development","item":"https:\/\/www.javacodegeeks.com\/category\/web-development"},{"@type":"ListItem","position":3,"name":"JavaScript","item":"https:\/\/www.javacodegeeks.com\/category\/web-development\/javascript"},{"@type":"ListItem","position":4,"name":"Parameterized tests in JavaScript with Jest"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/b1a0b2657d5dd2459806446ac66d2d52","name":"Rafal Borowiec","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/e24680b2ba3dfc13759acf6c1f125e54356bc533e0befe953fea365cadcdaffb?s=96&d=mm&r=g","caption":"Rafal Borowiec"},"description":"Software developer, Team Leader, Agile practitioner, occasional blogger, lecturer. Open Source enthusiast, quality oriented and open-minded.","sameAs":["http:\/\/blog.codeleak.pl\/","http:\/\/pl.linkedin.com\/in\/borowiec\/","https:\/\/x.com\/https:\/\/twitter.com\/kolorobot"],"url":"https:\/\/www.javacodegeeks.com\/author\/rafal-borowiec"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/112326","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/516"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=112326"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/112326\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/20900"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=112326"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=112326"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=112326"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}