mercredi 9 décembre 2015

React component undefined in jasmine test

I have this simple React component written in Coffeescript

Views.Person.Form = React.createClass

  render: ->
    React.DOM.form
      className: "form-inline"
      React.DOM.div
        className: 'form-group'
        React.DOM.input
          type: 'text'
          className: 'form-control'
          name: 'fullname

I drive test using Jasmine (my current version is 2.3.4), and this is my test

describe "Views.Person.Form", ->
  it "shoud render with the correct DOM", ->
    component = React.createElement(Views.Person.Form)
    form = React.addons.TestUtils.renderIntoDocument component

    expect(form.getDOMNode().className).toEqual "form-inline"

Running this test throws an "Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: undefined" error. Evidently Views.Person.Form component is not defined.

I'm using React with addons 0.14.3 on Rails 3.

Aucun commentaire:

Enregistrer un commentaire