Skip to content

Commit

Permalink
Implement .match() assertion (closes DevExpress#1038)
Browse files Browse the repository at this point in the history
  • Loading branch information
inikulin committed Dec 15, 2016
1 parent 8eaff38 commit 2a8e101
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/api/assertion.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
22 changes: 22 additions & 0 deletions test/functional/fixtures/api/es-next/assertions/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/);
});

0 comments on commit 2a8e101

Please sign in to comment.