d4nyll/jest-matcher-one-of

View on GitHub
src/index.js

Summary

Maintainability
A
0 mins
Test Coverage
expect.extend({
  toBeOneOf(received, argument) {
    const validValues = Array.isArray(argument) ? argument : [argument];
    const pass = validValues.includes(received);
    if (pass) {
      return {
        message: () => (
          `expected ${received} not to be one of [${validValues.join(', ')}]`
        ),
        pass: true,
      };
    }
    return {
      message: () => (`expected ${received} to be one of [${validValues.join(', ')}]`),
      pass: false,
    };
  },
});