$chiubaca / notes / fleeting / 2021-05-27
  • Used jests test.each for the first time. The syntax is kinda confusing but I grokked it in the end.
    test.each([
      [1, 1, 2],
      [1, 2, 3],
      [2, 1, 3],
    ])(".add(%i, %i)", (a, b, expected) => {
      expect(a + b).toBe(expected);
    });
    The array of arrays passed is the variables and expected params for your test. The last item in the array is the expected value . You can have any number of values before which represent the aruguments or conditions of your text.
Edit on GitHub ✏️

Hey I'm Alex Chiu 👋. These are my notes for literally anything.

I'm using the Zettelkasten method to organise my thoughts here.

My more polished writings are published to my main blog at chiubaca.com

Follow me on: Github / X (Twitter) / Mastodon / LinkedIn