mirror of
https://github.com/usebruno/bruno.git
synced 2024-11-22 07:53:34 +01:00
feat: added custom assertion for chaijs for match() method
This commit is contained in:
parent
dea95664b9
commit
78251c530c
@ -20,6 +20,25 @@ chai.use(function (chai, utils) {
|
||||
});
|
||||
});
|
||||
|
||||
// Custom assertion for matching regex
|
||||
chai.use(function (chai, utils) {
|
||||
chai.Assertion.addMethod('match', function (regex) {
|
||||
const obj = this._obj;
|
||||
let match = false;
|
||||
if(obj === undefined) {
|
||||
match = false;
|
||||
} else {
|
||||
match = regex.test(obj);
|
||||
}
|
||||
|
||||
this.assert(
|
||||
match,
|
||||
`expected ${utils.inspect(obj)} to match ${regex}`,
|
||||
`expected ${utils.inspect(obj)} not to match ${regex}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
/**
|
||||
* Assertion operators
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user