-
-
Notifications
You must be signed in to change notification settings - Fork 225
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create pass/fail error messages only if required
- Loading branch information
1 parent
e55d99c
commit ad5c5a2
Showing
71 changed files
with
1,057 additions
and
1,016 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
export function toBeAfter(date, after) { | ||
const { printReceived, matcherHint } = this.utils; | ||
const passMessage = | ||
matcherHint('.not.toBeAfter', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after ${printReceived(after)} but received:\n` + | ||
` ${printReceived(date)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeAfter', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after ${printReceived(after)} but received:\n` + | ||
` ${printReceived(date)}`; | ||
|
||
const pass = date > after; | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeAfter', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after ${printReceived(after)} but received:\n` + | ||
` ${printReceived(date)}` | ||
: matcherHint('.toBeAfter', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after ${printReceived(after)} but received:\n` + | ||
` ${printReceived(date)}`, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export function toBeAfterOrEqualTo(actual, expected) { | ||
const { printReceived, matcherHint } = this.utils; | ||
|
||
const passMessage = | ||
matcherHint('.not.toBeAfterOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeAfterOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const pass = actual >= expected; | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeAfterOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}` | ||
: matcherHint('.toBeAfterOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be after or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export function toBeArray(expected) { | ||
const { matcherHint, printReceived } = this.utils; | ||
|
||
const passMessage = | ||
matcherHint('.not.toBeArray', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be an array received:\n' + | ||
` ${printReceived(expected)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeArray', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be an array received:\n' + | ||
` ${printReceived(expected)}`; | ||
|
||
const pass = Array.isArray(expected); | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeArray', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be an array received:\n' + | ||
` ${printReceived(expected)}` | ||
: matcherHint('.toBeArray', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be an array received:\n' + | ||
` ${printReceived(expected)}`, | ||
}; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
export function toBeBefore(actual, expected) { | ||
const { matcherHint, printReceived } = this.utils; | ||
const passMessage = | ||
matcherHint('.not.toBeBefore', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeBefore', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const pass = actual < expected; | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeBefore', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}` | ||
: matcherHint('.toBeBefore', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export function toBeBeforeOrEqualTo(actual, expected) { | ||
const { matcherHint, printReceived } = this.utils; | ||
|
||
const passMessage = | ||
matcherHint('.not.toBeBeforeOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeBeforeOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const pass = actual <= expected; | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeBeforeOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}` | ||
: matcherHint('.toBeBeforeOrEqualTo', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be before or equal to ${printReceived(expected)} but received:\n` + | ||
` ${printReceived(actual)}`, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export function toBeBetween(actual, startDate, endDate) { | ||
const { matcherHint, printReceived } = this.utils; | ||
|
||
const passMessage = | ||
matcherHint('.not.toBeBetween', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be between ${printReceived(startDate)} and ${printReceived(endDate)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeBetween', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be between ${printReceived(startDate)} and ${printReceived(endDate)} but received:\n` + | ||
` ${printReceived(actual)}`; | ||
|
||
const pass = actual >= startDate && actual <= endDate; | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeBetween', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be between ${printReceived(startDate)} and ${printReceived(endDate)} but received:\n` + | ||
` ${printReceived(actual)}` | ||
: matcherHint('.toBeBetween', 'received', '') + | ||
'\n\n' + | ||
`Expected date to be between ${printReceived(startDate)} and ${printReceived(endDate)} but received:\n` + | ||
` ${printReceived(actual)}`, | ||
}; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export function toBeBoolean(actual) { | ||
const { matcherHint, printReceived } = this.utils; | ||
|
||
const passMessage = | ||
matcherHint('.not.toBeBoolean', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be of type boolean, received:\n' + | ||
` ${printReceived(actual)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeBoolean', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be of type boolean, received:\n' + | ||
` ${printReceived(actual)}`; | ||
|
||
const pass = typeof actual === 'boolean' || actual instanceof Boolean; | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeBoolean', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be of type boolean, received:\n' + | ||
` ${printReceived(actual)}` | ||
: matcherHint('.toBeBoolean', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be of type boolean, received:\n' + | ||
` ${printReceived(actual)}`, | ||
}; | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
export function toBeDateString(actual) { | ||
const { matcherHint, printReceived } = this.utils; | ||
|
||
const passMessage = | ||
matcherHint('.not.toBeDateString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be a date string received:\n' + | ||
` ${printReceived(actual)}`; | ||
|
||
const failMessage = | ||
matcherHint('.toBeDateString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be a date string received:\n' + | ||
` ${printReceived(actual)}`; | ||
|
||
const pass = !isNaN(Date.parse(actual)); | ||
|
||
return { pass, message: () => (pass ? passMessage : failMessage) }; | ||
return { | ||
pass, | ||
message: () => | ||
pass | ||
? matcherHint('.not.toBeDateString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to not be a date string received:\n' + | ||
` ${printReceived(actual)}` | ||
: matcherHint('.toBeDateString', 'received', '') + | ||
'\n\n' + | ||
'Expected value to be a date string received:\n' + | ||
` ${printReceived(actual)}`, | ||
}; | ||
} |
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
Oops, something went wrong.