React / Enzyme testing value of HTML Label?












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: jdoe@foo.bar, 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."









share|improve this question
























  • What's wrong with current code? I think its correctly checking
    – Just code
    Nov 20 at 6:24










  • Post edited to show test failed message
    – arcade16
    Nov 20 at 6:26
















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: jdoe@foo.bar, 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."









share|improve this question
























  • What's wrong with current code? I think its correctly checking
    – Just code
    Nov 20 at 6:24










  • Post edited to show test failed message
    – arcade16
    Nov 20 at 6:26














0












0








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: jdoe@foo.bar, 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."









share|improve this question















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: jdoe@foo.bar, 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."






javascript html reactjs unit-testing enzyme






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 6:26

























asked Nov 20 at 6:21









arcade16

755826




755826












  • What's wrong with current code? I think its correctly checking
    – Just code
    Nov 20 at 6:24










  • Post edited to show test failed message
    – arcade16
    Nov 20 at 6:26


















  • What's wrong with current code? I think its correctly checking
    – Just code
    Nov 20 at 6:24










  • Post edited to show test failed message
    – arcade16
    Nov 20 at 6:26
















What's wrong with current code? I think its correctly checking
– Just code
Nov 20 at 6:24




What's wrong with current code? I think its correctly checking
– Just code
Nov 20 at 6:24












Post edited to show test failed message
– arcade16
Nov 20 at 6:26




Post edited to show test failed message
– arcade16
Nov 20 at 6:26












1 Answer
1






active

oldest

votes


















1














with this reference, expect statement should be like below:



expect(wrapper.find('[data-test-id="userInfo"]').text().equals("Logged in as: jdoe@foo.bar, Role: Subscriber")).to.equal(true);





share|improve this answer





















  • Thanks, but it still fails with the same message.
    – arcade16
    Nov 20 at 6:43










  • wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
    – Srd Mathur
    Nov 20 at 6:47










  • I get "TypeError: Cannot read property 'text' of undefined" when trying that
    – arcade16
    Nov 20 at 6:53










  • try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
    – Srd Mathur
    Nov 20 at 7:04












  • TypeError: Cannot read property 'text' of undefined on both of those :/
    – arcade16
    Nov 20 at 7:09











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387323%2freact-enzyme-testing-value-of-html-label%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














with this reference, expect statement should be like below:



expect(wrapper.find('[data-test-id="userInfo"]').text().equals("Logged in as: jdoe@foo.bar, Role: Subscriber")).to.equal(true);





share|improve this answer





















  • Thanks, but it still fails with the same message.
    – arcade16
    Nov 20 at 6:43










  • wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
    – Srd Mathur
    Nov 20 at 6:47










  • I get "TypeError: Cannot read property 'text' of undefined" when trying that
    – arcade16
    Nov 20 at 6:53










  • try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
    – Srd Mathur
    Nov 20 at 7:04












  • TypeError: Cannot read property 'text' of undefined on both of those :/
    – arcade16
    Nov 20 at 7:09
















1














with this reference, expect statement should be like below:



expect(wrapper.find('[data-test-id="userInfo"]').text().equals("Logged in as: jdoe@foo.bar, Role: Subscriber")).to.equal(true);





share|improve this answer





















  • Thanks, but it still fails with the same message.
    – arcade16
    Nov 20 at 6:43










  • wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
    – Srd Mathur
    Nov 20 at 6:47










  • I get "TypeError: Cannot read property 'text' of undefined" when trying that
    – arcade16
    Nov 20 at 6:53










  • try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
    – Srd Mathur
    Nov 20 at 7:04












  • TypeError: Cannot read property 'text' of undefined on both of those :/
    – arcade16
    Nov 20 at 7:09














1












1








1






with this reference, expect statement should be like below:



expect(wrapper.find('[data-test-id="userInfo"]').text().equals("Logged in as: jdoe@foo.bar, Role: Subscriber")).to.equal(true);





share|improve this answer












with this reference, expect statement should be like below:



expect(wrapper.find('[data-test-id="userInfo"]').text().equals("Logged in as: jdoe@foo.bar, Role: Subscriber")).to.equal(true);






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 20 at 6:35









Srd Mathur

113




113












  • Thanks, but it still fails with the same message.
    – arcade16
    Nov 20 at 6:43










  • wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
    – Srd Mathur
    Nov 20 at 6:47










  • I get "TypeError: Cannot read property 'text' of undefined" when trying that
    – arcade16
    Nov 20 at 6:53










  • try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
    – Srd Mathur
    Nov 20 at 7:04












  • TypeError: Cannot read property 'text' of undefined on both of those :/
    – arcade16
    Nov 20 at 7:09


















  • Thanks, but it still fails with the same message.
    – arcade16
    Nov 20 at 6:43










  • wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
    – Srd Mathur
    Nov 20 at 6:47










  • I get "TypeError: Cannot read property 'text' of undefined" when trying that
    – arcade16
    Nov 20 at 6:53










  • try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
    – Srd Mathur
    Nov 20 at 7:04












  • TypeError: Cannot read property 'text' of undefined on both of those :/
    – arcade16
    Nov 20 at 7:09
















Thanks, but it still fails with the same message.
– arcade16
Nov 20 at 6:43




Thanks, but it still fails with the same message.
– arcade16
Nov 20 at 6:43












wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
– Srd Mathur
Nov 20 at 6:47




wrapper.find() returns an array of the results. I guess you should try wrapper.find('[data-test-id="userInfo"]')[0].text()
– Srd Mathur
Nov 20 at 6:47












I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 at 6:53




I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 at 6:53












try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
– Srd Mathur
Nov 20 at 7:04






try with wrapper.find('label#userInfo') or wrapper.find('#userInfo').
– Srd Mathur
Nov 20 at 7:04














TypeError: Cannot read property 'text' of undefined on both of those :/
– arcade16
Nov 20 at 7:09




TypeError: Cannot read property 'text' of undefined on both of those :/
– arcade16
Nov 20 at 7:09


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387323%2freact-enzyme-testing-value-of-html-label%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy