Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation implies expect(...).to.have.string(/foo/) should use RegExp matching #1156

Closed
mikesamuel opened this issue May 10, 2018 · 1 comment

Comments

@mikesamuel
Copy link

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?' } }
@meeber
Copy link
Contributor

meeber commented May 10, 2018

@mikesamuel Good catch, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants