question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[SOLVED][Jest] Testing fails when using Input component

See original GitHub issue

Explain what you did Test a component that wraps RNE’s Input component.

Expected behaviour Test should pass without error

Describe the bug Using the Input component results to a TypeError: Cannot read property 'default' of undefined error. Other components work just fine. Updates:

  • I found out that it’s not just the Input component. It’s also happening with these other components:

  • The error seems to only occur when testing. I tried running the app on my device and it’s working.

  • CheckBox

  • Icon

  • SearchBar

  • PricingCard (as a result of rendering Icon)

  • SocialIcon (as a result of rendering icon)

To Reproduce I’m using the TypeScript template of react-native. Setup with react-native-navigation. Using yarn workspaces + Lerna. Added testing using ts-jest + react-native-testing-library after. Encountered an error with Jest that was fixed by adding babel-core@7.0.0-bridge.0.

  1. Clone the sample repository. This is a stripped down repository without Yarn Workspaces + Lerna. It’s also only using react-test-renderer for snapshot testing. It contains a Hello component that renders an Input component from RNE. The test for this component is just a snapshot test.
  2. yarn install
  3. yarn jest

Possible Solution Can’t think of anything that might be causing this issue as of now. I think it’s an issue on my test environment setup as the error only occurs during testing.

Screenshots jesterror

Your Environment (please complete the following information):

software version
react-native-elements 1.0.0-beta5
react-native 0.57.5
yarn 1.12.3

Solution Use js-with-babel instead of the defaults preset from ts-jest/presets.

// jest.config.js
// const { jsWithBabel: tsjPreset } = require('ts-jest/presets');

module.exports = {
  // [...]
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
kdbcincocommented, Nov 23, 2018

@iRoachie Hey! I’ve resolved the issue. It’s got something to do with the ts-jest preset used. I was using the defaults ts-jest preset. Tried changing it to jsWithBabel and I’m not getting the aforementioned error anymore. Updating the issue. Thanks @iRoachie

References:

0reactions
kdbcincocommented, Nov 23, 2018

@iRoachie Hello! Here’s the repo. I found out that it’s not just the Input component. It’s also happening with these other components:

  • CheckBox
  • Icon
  • SearchBar
  • PricingCard (as a result of rendering Icon)
  • SocialIcon (as a result of rendering icon)
Read more comments on GitHub >

github_iconTop Results From Across the Web

test fails in jest, passes in jasmine for an angular directive with ...
So testing with jest I needed a second fixture. ... detectChanges call twice by setting auto detect changes while creating test component
Read more >
Simulating user input - Vue Testing Handbook
Let's take a look at how to use trigger and Jest mocks to verify our components are working correctly. The source code for...
Read more >
Testing Components depending on Services - Testing Angular
How to write unit and integration tests for Components with Service ... the ServiceCounterComponent does not have Inputs or Outputs to test.
Read more >
React Testing Library Tutorial – How to Write Unit Tests for ...
In this tutorial, you will learn how to confidently write unit tests using the Testing Library [https://testing-library.com/].
Read more >
Testing Workflow for Web Components - DEV Community ‍ ‍
Learn to test and debug your web component with open-wc tools so you ... FAILED TESTS: a11y input ✖ has a static shadowDom...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found