Jest/Jasmine .toContain() fails even though matching values are present

313
January 29, 2017, at 1:40 PM

I'm writing a simple React application with a Button component, which looks like this:

import React, { Component } from 'react';
// shim to find stuff
Array.prototype.contains = function (needle) {
  for (var i = 0; i < this.length; i++) {
       if (this[i] == needle) return true;
   }
   return false;
};
class Button extends Component {
  propTypes: {
    text: React.PropTypes.string.isRequired,
    modifiers: React.PropTypes.array
  }
  render() {
    return(
      <span className={this.displayModifiers()}>{this.props.text}</span>
    );
  }
  displayModifiers() {
    const modifiers = this.props.modifiers || ["default"];
    if (modifiers.contains("default") ||
      modifiers.contains("danger")  ||
      modifiers.contains("success")) {
      // do nothing
    } else {
      // add default
      modifiers.push("defualt");
    }
    var classNames = "btn"
    for (var i = 0; i < modifiers.length; i++) {
      classNames += " btn-" + modifiers[i]
    }
    return(classNames);
  }
}
export default Button;

I then wrote this to test it:

it("contains the correct bootstrap classes", () => {
  expect(mount(<Button modifiers={["flat"]}/>).html()).toContain("<span class=\"btn btn-flat btn-default\"></span>");
});

That code should pass, but I receive the following error message:

expect(string).toContain(value)
Expected string:
  "<span class=\"btn btn-flat btn-defualt\"></span>"
To contain value:
  "<span class=\"btn btn-flat btn-default\"></span>"
  at Object.it (src\__tests__\Button.test.js:42:293)

Any ideas why this is not passing?

READ ALSO
My node.js GET call returns an empty array from mongo .find()

My node.js GET call returns an empty array from mongo .find()

In this question I believe my configjs, model

271
How to detect that a burst of related events is done, and then emit one event

How to detect that a burst of related events is done, and then emit one event

My first question! I really do want to ask it right, so please help me improve it if I could have asked it better

219
Getting .filter to work with .map from JSON object in React.Js

Getting .filter to work with .map from JSON object in React.Js

I am trying to get my second dropdown to populate based on what is selected in the first dropdown

473