4

I am using test.each to run through some combinations of input data for a function:

const combinations = [
  [0,0],
  [1,0], // this combination doesn't work, I want to skip it
  [0,1],
  [1,0],
  [1,1],
]

describe('test all combinations', () => {
  test.each(combinations)(
    'combination a=%p and b=%p works',
    (a,b,done) => {
      expect(foo(a,b).toEqual(bar))
  });
});

Now, some of these combinations don't currently work and I want to skip those tests for the time being. If I just had one test I would simply do test.skip, but I don't know how this works if I want to skip some specific values in the input array.

1 Answer 1

4

Unfortunately jest doesn't support the annotations for skipping elements of combinations. You could do something like this, where you filter out the elements you do not want using a simple function (I have written one quickly, you can improve on it)

const combinations = [
  [0,0],
  [1,0], // this combination doesn't work, I want to skip it
  [0,1],
  [1,0],
  [1,1],
]
const skip = [[1,0]];
const combinationsToTest = combinations.filter(item => 
      !skip.some(skipCombo => 
            skipCombo.every( (a,i) => a === item[i])
            )
      )           

describe('test all combinations', () => {
  test.each(combinationsToTest)(
    'combination a=%p and b=%p works',
    (a,b,done) => {
      expect(foo(a,b).toEqual(bar))
  });
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.