Testing With Jest
See original GitHub issueI’m having an issue when trying to test with jest
import { Text } from "native-base"
it('should render the component correctly', () => {
const component = shallow(<Text>Hello World</Text>)
expect(component.find(Text).text()).toEqual('Hello World')
})
but getting error
Method “text” is meant to be run on 1 node. 0 found instead.
4 | const component = shallow(<Text>Hello World</Text>)
5 | console.log(component.debug())
> 6 | expect(component.find(Text).text()).toEqual('Hello World')
| ^
7 | })
8 |
at ShallowWrapper.single (node_modules/enzyme/src/ShallowWrapper.js:1636:13)
at ShallowWrapper.text (node_modules/enzyme/src/ShallowWrapper.js:1079:12)
at Object.text (src/__tests__/App.test.js:6:33)
But if i log the component using
console.log(component.debug())
I can see
<Text virtual={[undefined]} style={{...}} uppercase={false}>
Hello World
</Text>
Except i’m not doing it properly
My jest config in package.json
"jest": {
"preset": "react-native",
"setupFilesAfterEnv": [
"./setupTests.js"
]
}
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Jest · Delightful JavaScript Testing
Jest is a JavaScript testing framework designed to ensure correctness of any JavaScript codebase. It allows you to write tests with an approachable, ......
Read more >Jest Tutorial for Beginners: Getting Started With JavaScript ...
Jest is a JavaScript test runner, that is, a JavaScript library for creating, running, and structuring tests. Jest ships as an NPM package,...
Read more >Jest Tutorial - JavaScript Unit Testing Using Jest Framework
Jest is a Javascript Testing framework built by Facebook. It is primarily designed for React (which is also built by Facebook) based apps...
Read more >Jest Testing Tutorial: 5 Easy Steps - Testim Blog
1. Install Jest Globally · 2. Create a Sample Project · 3. Add Jest to the Project · 4. Write Your First Test...
Read more >What Is Jest – A Tutorial on How to Use Jest - LambdaTest
Jest is a JavaScript-based framework for testing React, React Native and other JavaScript-based applications. In many cases, unit tests don't provide accurate ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’m not quite sure if it’s the correct solution to this, but adding @codler to
transformIgnorePatterns
removes the error for me.Example:
"jest" : { "transformIgnorePatterns": [ "/node_modules/(?!(jest-)?@codler)" ] }
Have you solved the issue? For me, I am having a different issue:
I am on native-base 2.13.13