Testing Mocha response with the --watch option, shows warnings only for the first time

I am testing a wet React component. I am trying to catch some warnings (via console ), mainly related to "Failed propType" and other warnings that React can give. However, I had to repeat other testing methods, as the test will show warnings for the first time.

Here is my 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 a new instance of Deck', function () { expect(result).to.exist; }); it('should have a default style', function () { expect(result.props.style).to.exist; }); it('should only allow children of type Card', function () { expect(result.props.children.length).to.exist; expect(result.props.children.length).to.equal(3); }); it('should allow one 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 to 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 just the first child with handlers'); it('should have only the first and second child with images'); it('should preload up to the determined number of images'); }) 

I see that for the first time to run (by typing npm run test , which simply calls mocha --watch --compilers js:babel/register --recursive ), it shows warnings and I can make fun of console.warn using sinon and Total:

first time

However, the second time I get no warnings, and the tests that I run with the console.warn spire will fail.

second time

Any idea what is going on here? I tried to reach out to Mocha Gitter, on the IRC React channel, go through documents and through mocha --help , but to no avail.

+6
source share

Source: https://habr.com/ru/post/987172/


All Articles