0

I want to test that my label component is properly parsing the data in the principal object.

This is my label:

<label id="userInfo"><b>Logged in as: </b>{principal.emailAddress}, <b>Role: </b>{userRole}</label>

And this is my test, which is not currently working:

describe("Testing User Info displaying correctly", () =>{
  it("when provided principal data, it should correctly combine the username and role", () => {
    expect(wrapper.find('[data-test-id="userInfo"]').text()).to.equal("Logged in as: [email protected], Role: Subscriber");
    });
});

How can I check that the value of my label, or more accurately the text between the tags, is being shown correctly?

Currently the test fails with the following message:

"Method “text” is only meant to be run on a single node. 0 found instead."
2
  • What's wrong with current code? I think its correctly checking Commented Nov 20, 2018 at 6:24
  • Post edited to show test failed message Commented Nov 20, 2018 at 6:26

1 Answer 1

1

with this reference, expect statement should be like below:

expect(wrapper.find('[data-test-id="userInfo"]').text().equals("Logged in as: [email protected], Role: Subscriber")).to.equal(true);
Sign up to request clarification or add additional context in comments.

5 Comments

Thanks, but it still fails with the same message.
wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
I get "TypeError: Cannot read property 'text' of undefined" when trying that
try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
TypeError: Cannot read property 'text' of undefined on both of those :/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.