diff --git a/src/api/assertion.js b/src/api/assertion.js index 772cc361d9c..ae8502bf9ba 100644 --- a/src/api/assertion.js +++ b/src/api/assertion.js @@ -133,4 +133,12 @@ export default class Assertion { notWithin (lo, hi, message, opts) { return this._enqueueAssertion('notWithin', message, opts, () => expect(this.actual).not.to.be.within(lo, hi, this.message)); } + + match (re, message, opts) { + return this._enqueueAssertion('match', message, opts, () => assert.match(this.actual, re, this.message)); + } + + notMatch (re, message, opts) { + return this._enqueueAssertion('notMatch', message, opts, () => assert.notMatch(this.actual, re, this.message)); + } } diff --git a/test/functional/fixtures/api/es-next/assertions/test.js b/test/functional/fixtures/api/es-next/assertions/test.js index 76d344dc40d..9f546459518 100644 --- a/test/functional/fixtures/api/es-next/assertions/test.js +++ b/test/functional/fixtures/api/es-next/assertions/test.js @@ -156,6 +156,28 @@ describe('[API] Assertions', function () { }); }); + it('Should perform .match() assertion', function () { + return runTests('./testcafe-fixtures/assertions-test.js', '.match() assertion', { + shouldFail: true, + only: 'chrome' + }) + .catch(function (errs) { + expect(errs[0]).contains("AssertionError: expected 'yo' to match /[x,z]o/"); + expect(errs[0]).contains("> 136 | .expect('yo').match(/[x,z]o/);"); + }); + }); + + it('Should perform .notMatch() assertion', function () { + return runTests('./testcafe-fixtures/assertions-test.js', '.notMatch() assertion', { + shouldFail: true, + only: 'chrome' + }) + .catch(function (errs) { + expect(errs[0]).contains("AssertionError: expected '42 hey' not to match /\\d+ hey/"); + expect(errs[0]).contains("> 142 | .expect('42 hey').notMatch(/\\d+ hey/);"); + }); + }); + it('Should retry assertion for selector results', function () { return runTests('./testcafe-fixtures/assertions-test.js', 'Selector result assertion', { only: 'chrome' }); }); diff --git a/test/functional/fixtures/api/es-next/assertions/testcafe-fixtures/assertions-test.js b/test/functional/fixtures/api/es-next/assertions/testcafe-fixtures/assertions-test.js index b0cc1f18b15..9544bbc953a 100644 --- a/test/functional/fixtures/api/es-next/assertions/testcafe-fixtures/assertions-test.js +++ b/test/functional/fixtures/api/es-next/assertions/testcafe-fixtures/assertions-test.js @@ -129,3 +129,15 @@ test('"timeout" option', async t => { .click('#setClass') .expect(el.hasClass('hey')).ok('message', { timeout: 500 }); }); + +test('.match() assertion', async t => { + await t + .expect('42 hey').match(/\d+ hey/) + .expect('yo').match(/[x,z]o/); +}); + +test('.notMatch() assertion', async t => { + await t + .expect('yo').notMatch(/[x,z]o/) + .expect('42 hey').notMatch(/\d+ hey/); +});