Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Method “text” is meant to be run on 1 node. 0 found instead #2545

Open
3 tasks done
smrititaneja18 opened this issue Nov 16, 2021 · 3 comments
Open
3 tasks done

Comments

@smrititaneja18
Copy link

smrititaneja18 commented Nov 16, 2021

Your environment

Test

API

  • mount
  • render

Version

library version
enzyme 3.11.0
react 16.13.1
react-dom 16.13.1
react-test-renderer ^10.0.4

Adapter

  • enzyme-adapter-react-16

I am getting this type of error while executing enzyme test case in React. Below is my test case. Can anyone please help.

context("testing case1", () => {

it("contains correct context notification text", () => {
const date = "2019-05-05"
const testOrder = Object.assign({}, XYZ, { type: ABC, status: A })
const textExpected = abc ${moment(date).format("DD.MM.YYYY")}
expect(renderCtxNotification(testOrder).find("section").text()).to.equal(textExpected)
})
})
const renderCtxNotification = (orderData) => mount(resolveOrderStatusContents(orderData).ctxNotification.renderContents(orderData)

**Below is the error:

Error: Method “text” is meant to be run on 1 node. 0 found instead.
at ReactWrapper.single (node_modules/enzyme/src/ReactWrapper.js:1168:13)
at ReactWrapper.text (node_modules/enzyme/src/ReactWrapper.js:629:17)**

section is present in .jsx file:

<section>
            <H4><LocalizedText locKey="text1" /></H4>
            <BodyText>
              <LocalizedTextWithPlaceholders locKey="text2" placeholders={[formatDate(date)]} />
            </BodyText>
          </section>
@ljharb
Copy link
Member

ljharb commented Nov 16, 2021

The code you provided has a syntax error; can you share the actual jsx being passed into mount? (i suggest avoiding over abstractions that hide away passing jsx directly into an enzyme wrapper, since they make tests much harder to understand and maintain)

What does .debug() say on the wrapper?

@smrititaneja18
Copy link
Author

i cannot just paste whole .jsx file here but this is the only chunk of code i have added (the section part) and while debugging my test case is going in default case. the condition is not satisfied and hence it is going in default case.

@ljharb
Copy link
Member

ljharb commented Nov 17, 2021

I understand, but it's pretty hard to make a reproducible test case without the entire component code, and the complete test code (including abstractions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants