reactjs - Testing React with mocha with --watch option, shows warnings only the first time -
i'm testing react component mocha. i'm trying catch warnings (through console
), related "failed proptype" , other warnings react can give. i've had recur other methods of testing since test show warnings first time.
here's test code:
var jsdom = require('mocha-jsdom'); var { expect, assert } = require('chai'); var sinon = require('sinon'); describe('deck', function() { jsdom(); var react = require('react/addons'); var testutils = react.addons.testutils; var deck, card, othermock; var renderer, result; beforeeach(function() { deck = require('../app/components/deck.js'); card = require('../app/components/card.js') othermock = react.createclass({ render: function() { return null } }); renderer = react.addons.testutils.createrenderer(); renderer.render( <deck> <othermock /> <othermock /> <othermock /> <card /> <card /> <card /> </deck> ); result = renderer.getrenderoutput(); }); aftereach(function() { }); it('should create new instance of deck', function () { expect(result).to.exist; }); it('should have default style', function () { expect(result.props.style).to.exist; }); it('should allow children of type card', function () { expect(result.props.children.length).to.exist; expect(result.props.children.length).to.equal(3); }); it('should allow 1 card', function() { var renderer = react.addons.testutils.createrenderer(); renderer.render( <deck> <card /> </deck> ); var result = renderer.getrenderoutput() expect(result).to.exist; expect(react.children.count(result.props.children)).to.equal(1); }); it('should render empty when passed incorrect children', function() { var renderer = react.addons.testutils.createrenderer(); renderer.render( <deck> <othermock /> </deck> ); var result = renderer.getrenderoutput() expect(result).to.exist; expect(react.children.count(result.props.children)).to.equal(0); }); it('should render when empty', function() { var renderer = react.addons.testutils.createrenderer(); renderer.render( <deck /> ); var result = renderer.getrenderoutput() expect(result).to.exist; }); it('should add keys children', function() { var index = react.children.count(result.props.children); react.children.foreach(result.props.children, function(child) { expect(child.props.cardindex).to.exist; expect(child.props.cardindex).to.equal(--index); }) }); it('should have first child handlers'); it('should have first , second child images'); it('should preload determined number of images'); })
what see first time run (typing npm run test
calls mocha --watch --compilers js:babel/register --recursive
) shows warnings , i'm able mock console.warn
sinon , everything:
however second time, don't warnings , tests console.warn
spy fail.
any idea going on here? i've tried reaching out in mocha's gitter, in irc's react channel, going through docs , through mocha --help
, no avail.
Comments
Post a Comment