Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specifically address parameterized/data-driven testing with Jasmine #170

Closed
jneuhaus20 opened this issue Oct 16, 2024 · 0 comments
Closed

Comments

@jneuhaus20
Copy link

I don't know the best place to add this, but since it's a touted feature in many frameworks, I feel like explicit guidance on parameterized/data-driven testing would be beneficial. Or if it exists, it's not discoverable.

There are several closed issues indicating it's available in (or one would need to create a) plugin, but this is misleading and gives the impression that it's not natively supported. (See jasmine/jasmine#900, jasmine/jasmine#741 (and PR jasmine/jasmine#527), and jasmine/jasmine#480.

However, by virtue of language capabilities and how jasmine works at runtime, this is actually 100% natively supported. Credit to jasmine/jasmine#900 (comment):

const cases = [
  {first: 3, second: 3, sum: 6},
  {first: 10, second: 4, sum: 14},
  {first: 7, second: 1, sum: 8}
];

for (const {first, second, sum} of cases) {
  it(`${first} plus ${second} is ${sum}`, function() {
    expect(first+second).toEqual(sum);
  });
}

Or even:

const integerCases = {
  positive: [
    {first: 3, second: 3, sum: 6},
    {first: 10, second: 4, sum: 14},
    {first: 7, second: 1, sum: 8}
  ],
  negative: [
    {first: -3, second: -3, sum: -6},
    {first: -10, second: -4, sum: -14},
    {first: -7, second: -1, sum: -8}
  ]
};

Object.entries(integerCases ).forEach(([type, cases]) => {
  describe(`when adding ${type} integers`, () => {
      cases.forEach(({first, second, sum}) => {
        it(`${first} plus ${second} is ${sum}`, function() {
          expect(first + second).toEqual(sum);
        });
      });
  });
});

The appropriate area of the docs should be amended to include this technique, in whatever style/manner best aligns with the existing examples. That way people don't think this common best practice is prohibitively difficult or unsupported, and look to a different framework instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant