Skip to content

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

Closed
@mikesamuel

Description

@mikesamuel

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?' } }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @mikesamuel@meeber

        Issue actions

          documentation implies `expect(...).to.have.string(/foo/)` should use RegExp matching · Issue #1156 · chaijs/chai