Created
October 4, 2017 08:26
-
-
Save marcelblijleven/70058042eb2054f43c18a24b8516a79e to your computer and use it in GitHub Desktop.
Jest: expect to be between two numbers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
expect.extend({ | |
toBeBetween(received, argumentOne, argumentTwo) { | |
if (argumentOne > argumentTwo) { | |
// Switch values | |
[argumentOne, argumentTwo] = [argumentTwo, argumentOne]; | |
} | |
const pass = (received >= argumentOne && received <= argumentTwo); | |
if (pass) { | |
return { | |
message: () => (`expected ${received} not to be between ${argumentOne} and ${argumentTwo}`), | |
pass: true | |
}; | |
} else { | |
return { | |
message: () => (`expected ${received} to be between ${argumentOne} and ${argumentTwo}`), | |
pass: false | |
} | |
} | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment