diff --git a/__test__/jest/__snapshots__/each.snapshot.test.js.snap b/__test__/jest/__snapshots__/each.snapshot.test.js.snap new file mode 100644 index 0000000..714d0c5 --- /dev/null +++ b/__test__/jest/__snapshots__/each.snapshot.test.js.snap @@ -0,0 +1,455 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`1 + 1 args are correct 1`] = ` +[ + { + "a": 1, + "b": 1, + "expected": 2, + }, +] +`; + +exports[`1 + 2 args are correct 1`] = ` +[ + { + "a": 1, + "b": 2, + "expected": 3, + }, +] +`; + +exports[`1 + 2 args are correct 2`] = ` +[ + { + "a": 1, + "b": 2, + "expected": 3, + }, +] +`; + +exports[`2 + 1 args are correct 1`] = ` +[ + { + "a": 2, + "b": 1, + "expected": 3, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -F: $a, $b 1`] = ` +[ + [ + { + "a": 2, + "b": 5, + }, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -F: $a, 42 1`] = ` +[ + { + "b": 42, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -F: 1, 1 1`] = ` +[ + { + "a": 1, + "b": 1, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -F: NaN, $b 1`] = ` +[ + { + "a": NaN, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -G: $a, $b 1`] = ` +[ + [ + { + "a": 2, + "b": 5, + }, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -G: $a, $b 2`] = ` +[ + { + "b": 42, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -G: $a, $b 3`] = ` +[ + { + "a": NaN, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -G: $a, $b 4`] = ` +[ + { + "a": 1, + "b": 1, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots -G: $a, $b 5`] = ` +[ + 43, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots 1 1 %n 1`] = ` +[ + 1, + 1, + 2, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots 1 2 %n 1`] = ` +[ + 1, + 2, + 3, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots 2 1 %n 1`] = ` +[ + 2, + 1, + 3, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots A: 1 %s %i 1`] = ` +[ + 1, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots A: NaN %s %i 1`] = ` +[ + [], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots A: NaN %s %i 2`] = ` +[ + {}, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots B: %i %s %n 1`] = `[]`; + +exports[`test.each names and values are correct, as verified by snapshots B: %i %s %n 2`] = `[]`; + +exports[`test.each names and values are correct, as verified by snapshots B: %i %s %n 3`] = `[]`; + +exports[`test.each names and values are correct, as verified by snapshots C: NaN %s %n 1`] = ` +[ + [], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots C: NaN %s %n 2`] = ` +[ + [], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots C: NaN %s %n 3`] = ` +[ + {}, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots D: %j %s %n 1`] = `[]`; + +exports[`test.each names and values are correct, as verified by snapshots D: {} %s %n 1`] = ` +[ + {}, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots D: {} %s %n 2`] = ` +[ + {}, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots E: NaN %s %n 1`] = ` +[ + [], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots E: NaN %s %n 2`] = ` +[ + {}, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots E: NaN %s %n 3`] = ` +[ + [ + {}, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots F: $a, $b 1`] = ` +[ + [ + { + "a": 2, + "b": 5, + }, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots F: $a, 42 1`] = ` +[ + { + "b": 42, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots F: 1, 1 1`] = ` +[ + { + "a": 1, + "b": 1, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots F: NaN, $b 1`] = ` +[ + { + "a": NaN, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots G: $a, $b 1`] = ` +[ + 43, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots G: $a, $b 2`] = ` +[ + { + "a": 1, + "b": 1, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots G: $a, $b 3`] = ` +[ + { + "a": NaN, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots G: $a, $b 4`] = ` +[ + { + "b": 42, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots G: $a, $b 5`] = ` +[ + [ + { + "a": 2, + "b": 5, + }, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots H: $a, $b 1`] = ` +[ + null, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots H: $a, $b 2`] = ` +[ + { + "a": 1, + "b": 1, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots H: $a, $b 3`] = ` +[ + { + "a": NaN, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots H: $a, $b 4`] = ` +[ + { + "b": 42, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots H: $a, $b 5`] = ` +[ + [ + { + "a": 2, + "b": 5, + }, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: $a, $b, $1$0 c,$c0|^@*$mw#o%M@$d 1`] = ` +[ + { + "k": 24, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: $a, $b, 3020 c,$c0|^@*$mw#o%M@$d 1`] = ` +[ + [ + 20, + 30, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: $a, 20, $1$0 c,$c0|^@*$mw#o%M@$d 1`] = ` +[ + X { + "b": 20, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: /y/, /y/, /y//y/ c,/y/|^@*/y/#o%M@/y/ 1`] = ` +[ + /y/, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: [], [], [][] c,[]|^@*[]#o%M@[] 1`] = ` +[ + [], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: {}, {}, {}{} c,{}|^@*{}#o%M@{} 1`] = ` +[ + {}, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: 1, 1, $1$0 c,$c0|^@*$mw#o%M@$d 1`] = ` +[ + { + "a": 1, + "b": 1, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots I: NaN, $b, $1$0 c,$c0|^@*$mw#o%M@$d 1`] = ` +[ + { + "a": NaN, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots J: $a, $b 1`] = ` +[ + 3, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots J: $a, $b 2`] = ` +[ + [], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots J: $a, $b 3`] = ` +[ + { + "a": 3, + "b": 1, + }, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots J: $a, $b 4`] = ` +[ + [ + { + "a": 1, + "b": 2, + }, + ], +] +`; + +exports[`test.each names and values are correct, as verified by snapshots static 1`] = ` +[ + 1, + 1, + 2, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots static 2`] = ` +[ + 1, + 2, + 3, +] +`; + +exports[`test.each names and values are correct, as verified by snapshots static 3`] = ` +[ + 2, + 1, + 3, +] +`; diff --git a/__test__/jest/each.snapshot.test.js b/__test__/jest/each.snapshot.test.js new file mode 100644 index 0000000..a014bd6 --- /dev/null +++ b/__test__/jest/each.snapshot.test.js @@ -0,0 +1,66 @@ +describe('test.each names and values are correct, as verified by snapshots', () => { + const iterate = (name, arr) => test.each(arr)(name, (...args) => expect(args).toMatchSnapshot()) + + iterate('static', [ + [1, 1, 2], + [1, 2, 3], + [2, 1, 3], + ]) + + iterate('%i %s %n', [ + [1, 1, 2], + [1, 2, 3], + [2, 1, 3], + ]) + + iterate('A: %i %s %i', [1, [], {}]) + iterate('B: %i %s %n', [[], [], []]) + iterate('C: %i %s %n', [[], [], {}]) + iterate('D: %j %s %n', [[], [{}], [{}]]) + iterate('E: %i %s %n', [[], {}, [{}]]) + + iterate('F: $a, $b', [{ a: 1, b: 1 }, { a: NaN }, { b: 42 }, [{ a: 2, b: 5 }]]) + + iterate('-F: $a, $b', [[{ a: 2, b: 5 }], { b: 42 }, { a: NaN }, { a: 1, b: 1 }]) + + iterate('G: $a, $b', [43, { a: 1, b: 1 }, { a: NaN }, { b: 42 }, [{ a: 2, b: 5 }]]) + + iterate('-G: $a, $b', [[{ a: 2, b: 5 }], { b: 42 }, { a: NaN }, { a: 1, b: 1 }, 43]) + + iterate('H: $a, $b', [null, { a: 1, b: 1 }, { a: NaN }, { b: 42 }, [{ a: 2, b: 5 }]]) + + class X {} + const x = new X() + x.b = 20 + + iterate('I: $a, $b, $1$0 c,$c0|^@*$mw#o%M@$d ', [ + /y/, + x, + {}, + { k: 24 }, + { a: 1, b: 1 }, + [], + [20, 30], + { a: NaN }, + ]) + + iterate('J: $a, $b', [3, [], { a: 3, b: 1 }, [{ a: 1, b: 2 }]]) +}) + +describe.each` + a | b | expected + ${1} | ${1} | ${2} + ${1} | ${2} | ${3} + ${1} | ${2} | ${3} + ${2} | ${1} | ${3} +`('$a + $b', (...args) => { + test(`args are correct`, () => { + expect(args).toMatchSnapshot() + }) + + const [{ a, b, expected }] = args + + test(`returns ${expected}`, () => { + expect(a + b).toBe(expected) + }) +})