Skip to content

Commit

Permalink
fix: prevent non-number use in number matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mefellows committed May 30, 2024
1 parent 7f58a25 commit 0db6f7f
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/v3/matchers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,12 +265,17 @@ export const decimal = (num?: number): Matcher<number> => {
* @param num Example value. If omitted a random integer value will be generated.
*/
export function number(num?: number): Matcher<number> {
if (num) {
if (num && typeof num === 'number') {
return {
'pact:matcher:type': 'number',
value: num,
};
}
if (num) {
throw new Error(
`The number matcher was passed '${num}' which is not a number.`
);
}
return {
'pact:generator:type': 'RandomInt',
'pact:matcher:type': 'number',
Expand Down

0 comments on commit 0db6f7f

Please sign in to comment.