Jest: mixup with sderr and stdout

Created on 30 May 2017  ยท  2Comments  ยท  Source: facebook/jest

I get the below error; Expected onBeforeMountComponent() parent and onSetChildren() to be consistent. according to https://github.com/facebook/react/issues/8692 This will be a non issue in React 16. I'm using Enzyme for this test suite, so I can't upgrade to the latest React Native untile Enzyme supports React 16.
I wanted to suppress the error for now, and I noticed something strange:

The test results get posted to stderr instead of stdout and when I turn on verbose logging it get even stranger, stdout gets the errors and most of what I would expect in stdout gets logged to stderr?
(the failing test and console log are on purpose)

The full output of my test:

$ npm test -- --coverage

> App@ test /media/dev/app
> jest "--coverage"

 FAIL  core/tests/components/settings.js
  โ— Console

    console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:71
      Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
    console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:71
      Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (7 has parents 0 and 5).
      Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (7 has parents 0 and 5).
          at invariant (/media/dj/dev/scan-app/node_modules/fbjs/lib/invariant.js:44:15)
          at Object.onSetChildren (/media/dj/dev/scan-app/node_modules/react/lib/ReactComponentTreeHook.js:186:78)
          at callHook (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:27:8)
          at emitEvent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:39:7)
          at Object.onSetChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:311:5)
          at ReactTestComponent.setChildrenForInstrumentation (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:157:38)
          at ReactTestComponent._updateChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:360:39)
          at ReactTestComponent.updateChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:299:12)
          at ReactTestComponent.receiveComponent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactTestRenderer.js:68:10)
          at Object.receiveComponent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactReconciler.js:125:22)
    console.log core/tests/components/settings.js:97
      [ 1, 3, 2 ]

  โ— settings functions work as expected โ€บ Settings.getAllSelected(product) works as expected

    expect(received).toEqual(expected)

    Expected value to equal:
      false
    Received:
      true

      at Object.<anonymous> (core/tests/components/settings.js:99:35)

 PASS  src/tests/view-test.js
 PASS  core/tests/components/details.js
 PASS  core/tests/components/scan.js
 PASS  core/tests/components/search.js
 PASS  core/tests/components/login.js
 PASS  core/tests/helpers/collections.js
 PASS  core/tests/helpers/search-guests.js
 PASS  core/tests/helpers/urls-dev.js
 PASS  core/tests/components/init.js
 PASS  core/tests/helpers/urls-prod.js

=============================== Coverage summary ===============================
Statements   : 43.59% ( 558/1280 )
Branches     : 33.72% ( 175/519 )
Functions    : 50% ( 227/454 )
Lines        : 49.26% ( 467/948 )
================================================================================

Test Suites: 1 failed, 10 passed, 11 total
Tests:       1 failed, 1 skipped, 34 passed, 36 total
Snapshots:   13 passed, 13 total
Time:        5.437s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

only stdout:

$ npm test -- --coverage 2>/dev/null

> App@ test /media/dev/app
> jest "--coverage"

Determining test suites to run...
=============================== Coverage summary ===============================
Statements   : 43.59% ( 558/1280 )
Branches     : 33.72% ( 175/519 )
Functions    : 50% ( 227/454 )
Lines        : 49.26% ( 467/948 )
================================================================================

only stderr:

$ npm test -- --coverage 1>/dev/null
 FAIL  core/tests/components/settings.js
  โ— Console

    console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:71
      Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.
    console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:71
      Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (7 has parents 0 and 5).
      Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (7 has parents 0 and 5).
          at invariant (/media/dj/dev/scan-app/node_modules/fbjs/lib/invariant.js:44:15)
          at Object.onSetChildren (/media/dj/dev/scan-app/node_modules/react/lib/ReactComponentTreeHook.js:186:78)
          at callHook (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:27:8)
          at emitEvent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:39:7)
          at Object.onSetChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:311:5)
          at ReactTestComponent.setChildrenForInstrumentation (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:157:38)
          at ReactTestComponent._updateChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:360:39)
          at ReactTestComponent.updateChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:299:12)
          at ReactTestComponent.receiveComponent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactTestRenderer.js:68:10)
          at Object.receiveComponent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactReconciler.js:125:22)
    console.log core/tests/components/settings.js:97
      [ 1, 3, 2 ]

  โ— settings functions work as expected โ€บ Settings.getAllSelected(product) works as expected

    expect(received).toEqual(expected)

    Expected value to equal:
      false
    Received:
      true

      at Object.<anonymous> (core/tests/components/settings.js:99:35)

 PASS  src/tests/view-test.js
 PASS  core/tests/components/search.js
 PASS  core/tests/components/details.js
 PASS  core/tests/components/scan.js
 PASS  core/tests/components/login.js
 PASS  core/tests/helpers/collections.js
 PASS  core/tests/helpers/search-guests.js
 PASS  core/tests/helpers/urls-dev.js
 PASS  core/tests/components/init.js
 PASS  core/tests/helpers/urls-prod.js

Test Suites: 1 failed, 10 passed, 11 total
Tests:       1 failed, 1 skipped, 34 passed, 36 total
Snapshots:   13 passed, 13 total
Time:        5.985s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

even more strange, when I turn on verbose the error gets logged to stdout..

 $ npm test -- --coverage --verbose 2>/dev/null

> Chipta@ test /media/dj/dev/scan-app
> jest "--coverage" "--verbose"

  console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:71
    Warning: ReactTestUtils has been moved to react-dom/test-utils. Update references to remove this warning.

  console.error node_modules/react-native/Libraries/Core/ExceptionsManager.js:71
    Warning: Exception thrown by hook while handling onSetChildren: Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (7 has parents 0 and 5).
    Invariant Violation: Expected onBeforeMountComponent() parent and onSetChildren() to be consistent (7 has parents 0 and 5).
        at invariant (/media/dj/dev/scan-app/node_modules/fbjs/lib/invariant.js:44:15)
        at Object.onSetChildren (/media/dj/dev/scan-app/node_modules/react/lib/ReactComponentTreeHook.js:186:78)
        at callHook (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:27:8)
        at emitEvent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:39:7)
        at Object.onSetChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactDebugTool.js:311:5)
        at ReactTestComponent.setChildrenForInstrumentation (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:157:38)
        at ReactTestComponent._updateChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:360:39)
        at ReactTestComponent.updateChildren (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactMultiChild.js:299:12)
        at ReactTestComponent.receiveComponent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactTestRenderer.js:68:10)
        at Object.receiveComponent (/media/dj/dev/scan-app/node_modules/react-test-renderer/lib/ReactReconciler.js:125:22)

  console.log core/tests/components/settings.js:97
    [ 1, 3, 2 ]


=============================== Coverage summary ===============================
Statements   : 43.59% ( 558/1280 )
Branches     : 33.72% ( 175/519 )
Functions    : 50% ( 227/454 )
Lines        : 49.26% ( 467/948 )
================================================================================
$ npm test -- --coverage --verbose 1>/dev/null
 FAIL  core/tests/components/settings.js
  โ— settings functions work as expected โ€บ Settings.getAllSelected(product) works as expected

    expect(received).toEqual(expected)

    Expected value to equal:
      false
    Received:
      true

      at Object.<anonymous> (core/tests/components/settings.js:99:35)

  Settings renders correctly
    โœ“ without event (32ms)
    โœ“ with event (30ms)
  settings functions work as expected
    โœ“ Settings.selectEventProduct(product) adds product as expected (22ms)
    โœ“ Settings.selectEventProduct(product) removes product as expected (18ms)
    โœ“ Settings.getSelected(product) works as expected (9ms)
    โœ• Settings.getAllSelected(product) works as expected (28ms)
    โœ“ Settings.selectAll() works as expected (20ms)
    โ—‹ skipped 1 test

 PASS  src/tests/view-test.js
  โœ“ LoginView renders correctly (39ms)
  โœ“ SettingsView renders correctly (10ms)
  โœ“ DrawerView renders correctly (65ms)
  โœ“ ScanView renders correctly (4ms)
  โœ“ ResultView renders correctly (17ms)
  โœ“ DetailsView renders correctly (19ms)

 PASS  core/tests/components/details.js
  โœ“ Details renderers correctly (47ms)

 PASS  core/tests/components/scan.js
  โœ“ Scan renderers correctly (22ms)

 PASS  core/tests/components/login.js
  โœ“ Login renders correctly (19ms)

 PASS  core/tests/components/search.js
  โœ“ Search renderers correctly (14ms)

 PASS  core/tests/helpers/collections.js
  models are created as expected
    โœ“ event is created properly (2ms)
    โœ“ guest is created properly (1ms)
    โœ“ event product is created properly
    โœ“ guest product is created properly (1ms)
  guest functions work as expected
    โœ“ guest.getFullName() returns full name of user (1ms)
    โœ“ guest.getFullName() returns email of guest if no name is found (1ms)
    โœ“ guest.getTotals() returns [used products, total products] (2ms)
  guest product functions work as expected
    โœ“ guestProduct.isValid() checks if the product is valid (1ms)
    โœ“ guestProduct.confirm(eventId, status) sets last use time on product (3ms)

 PASS  core/tests/helpers/search-guests.js
  searchGuests works as expected
    โœ“ searchGuests works as expected without searchTerm (1ms)
    โœ“ searchGuests works as expected with name (3ms)
    โœ“ searchGuests works as expected with barcode (2ms)

 PASS  core/tests/helpers/urls-dev.js
  โœ“ makeGuestProductUrl works as expected
  URLconfig is correct for dev
    โœ“ ajaxURL
    โœ“ socketURL (1ms)

 PASS  core/tests/components/init.js
  โœ“ Init renders correctly (5ms)

 PASS  core/tests/helpers/urls-prod.js
  URLconfig is correct for prod
    โœ“ ajaxURL
    โœ“ socketURL

Test Suites: 1 failed, 10 passed, 11 total
Tests:       1 failed, 1 skipped, 34 passed, 36 total
Snapshots:   13 passed, 13 total
Time:        5.485s
Ran all test suites.
npm ERR! Test failed.  See above for more details.

Most helpful comment

pass or fail is not error, it is expected output.
error is error, not expected output.

I can only find it strange.
Is there documentation on this I could read?

All 2 comments

This is how it works in Jest and it's not a bug.

pass or fail is not error, it is expected output.
error is error, not expected output.

I can only find it strange.
Is there documentation on this I could read?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

eldh picture eldh  ยท  84Comments

iffy picture iffy  ยท  137Comments

calebmer picture calebmer  ยท  72Comments

paularmstrong picture paularmstrong  ยท  66Comments

vitalibozhko picture vitalibozhko  ยท  138Comments