Closed
Description
http://www.chaijs.com/api/bdd/#method_string says
expect('foobar').to.have.string(/taco/, 'nooo why fail??');
expect('foobar', 'nooo why fail??').to.have.string(/taco/);
This seems to suggest that one can pass a RegExp
to match against.
It's possible that this was copy/pasted mistakenly from the previous section on .to.match(/.../)
.have.string
does not do RegExp
matching.
> grep chai package-lock.json
"chai": {
"resolved": "https://registry.npmjs.org/chai/-/chai-4.1.2.tgz",
> node -e "console.log(require('chai').expect('taco').to.have.string(/taco/, 'nooo why fail?'));"
/Users/msamuel/work/jsconf.eu.2018/node_modules/chai/lib/chai/assertion.js:141
throw new AssertionError(msg, {
^
AssertionError: nooo why fail?: expected 'taco' to contain /taco/
at [eval]:1:52
...
vs
> node -e "console.log(require('chai').expect('taco').to.match(/taco/, 'nooo why fail?'));"
Assertion {
__flags:
{ ssfi: [Function: proxyGetter],
lockSsfi: undefined,
object: 'taco',
message: 'nooo why fail?' } }
Activity
.string
example #1157meeber commentedon May 10, 2018
@mikesamuel Good catch, thanks!