jest-matcher-one-of
Advanced tools
Comparing version 0.1.0 to 0.1.1
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"main": "src/index.js", | ||
@@ -14,9 +14,14 @@ "author": "Daniel Li <dan@danyll.com>", | ||
"devDependencies": { | ||
"eslint": "^4.11.0", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"jest": "^21.2.1" | ||
}, | ||
"engines": { | ||
"node" : ">6.4.0" | ||
"node": ">6.4.0" | ||
}, | ||
"scripts": { | ||
"test": "jest" | ||
"fix": "npm run lint -- --fix", | ||
"lint": "eslint src/index.js", | ||
"test": "npm run lint && jest" | ||
}, | ||
@@ -23,0 +28,0 @@ "keywords": [ |
expect.extend({ | ||
toBeOneOf(received, argument) { | ||
if(!Array.isArray(argument)) { | ||
argument = [argument]; | ||
} | ||
const pass = argument.includes(received); | ||
const validValues = Array.isArray(argument) ? argument : [argument]; | ||
const pass = validValues.includes(received); | ||
if (pass) { | ||
return { | ||
message: () => ( | ||
`expected ${received} not to be one of [${argument.join(', ')}]` | ||
`expected ${received} not to be one of [${validValues.join(', ')}]` | ||
), | ||
pass: true, | ||
}; | ||
} else { | ||
return { | ||
message: () => (`expected ${received} to be one of [${argument.join(', ')}]`), | ||
pass: false, | ||
}; | ||
} | ||
return { | ||
message: () => (`expected ${received} to be one of [${validValues.join(', ')}]`), | ||
pass: false, | ||
}; | ||
}, | ||
}); |
Sorry, the diff of this file is not supported yet
105209
8
35
4