jeudi 2 juillet 2015

Node.js+React automating tests with Jest

I am currently trying to test my Node.js+React components using Jest. I've installed jest-cli and created a task on my gulpfile to run 'npm test'.

I somehow followed the instructions found here: http://ift.tt/1IsVJgu

And went to the project git repo to find how to configure some other stuff.

When I run the command 'gulp test' however, apparently all I get is the eslint code validation. I don't think my tests are running at all.

my relevant folder structure is as follows:

/__tests__
    searchComponent-spec.js
/src
    /components
        /Search
            Search.js
package.json
gulpfile.babel.js

there are many other stuff but I don't believe they are relevant.

My Search.js

/*! React Starter Kit | MIT License | http://ift.tt/1ITr4UN */

import React, { PropTypes } from 'react';
import styles from './Search.less';
import withStyles from '../../decorators/withStyles';
import Link from '../../utils/Link';

@withStyles(styles)
class Search {

  static contextTypes = {
    onSetTitle: PropTypes.func.isRequired
  };

  render() {
    let title = 'Pesquisa de desenvolvedores';
    this.context.onSetTitle(title);
    return (
      <div className="Search">
        <div className="Search-container">
          <a className="Search-brand" href="/" onClick={Link.handleClick}>
            <span className="Search-brandTxt">Dev-Shop</span>
          </a>
          <div className="Search-banner">
            <h1 className="Search-bannerTitle">Loja de desenvolvedores</h1>
          </div>
        </div>
      </div>
    );
  }

}

export default Search;

My searchComponent-spec.js:

/**
 * Created by urielbertoche on 02/07/15.
 */
"use strict";

jest.dontMock('../src/components/Search/Search.js');

describe('Search', function () {
  var React = require('react/addons');
  var TestUtils = React.addons.TestUtils;
  var Search;

  beforeSearch(function () {
    Search = require('../src/components/Search');
  });

  it('should exists', function () {
    // Render into document
    var search = TestUtils.renderIntoDocument(<Search />);
    expect(TestUtils.isCompositeComponent(search)).toBeTruthy();
  });
});

anyone got any idea why my tests may not be running? Thanks a lot

Aucun commentaire:

Enregistrer un commentaire