Trying to create a Custom Matcher that checks for a specific number of occurrences of a particular string within another string. Here's my approach:
var customMatcher = {
checkOccurrences: function (expectedString, expectedCount) {
return {
compare: function(actualString){
actualString.match(new RegExp(expectedString, "g") || []).length == expectedCount;
}
}
}
}
Encountering an error when running the code:
TypeError: Cannot read property 'pass' of undefined
The test setup looks like this:
expect(inputString).checkOccurrences("&", 2);
The expectation is for the input string to have exactly two occurrences of "&". What could be the issue here?