React / Enzyme testing value of HTML Label?
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
add a comment |
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
What's wrong with current code? I think its correctly checking
– Just code
Nov 20 '18 at 6:24
Post edited to show test failed message
– arcade16
Nov 20 '18 at 6:26
add a comment |
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
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
javascript html reactjs unit-testing enzyme
edited Nov 20 '18 at 6:26
arcade16
asked Nov 20 '18 at 6:21
arcade16arcade16
7711028
7711028
What's wrong with current code? I think its correctly checking
– Just code
Nov 20 '18 at 6:24
Post edited to show test failed message
– arcade16
Nov 20 '18 at 6:26
add a comment |
What's wrong with current code? I think its correctly checking
– Just code
Nov 20 '18 at 6:24
Post edited to show test failed message
– arcade16
Nov 20 '18 at 6:26
What's wrong with current code? I think its correctly checking
– Just code
Nov 20 '18 at 6:24
What's wrong with current code? I think its correctly checking
– Just code
Nov 20 '18 at 6:24
Post edited to show test failed message
– arcade16
Nov 20 '18 at 6:26
Post edited to show test failed message
– arcade16
Nov 20 '18 at 6:26
add a comment |
1 Answer
1
active
oldest
votes
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);
Thanks, but it still fails with the same message.
– arcade16
Nov 20 '18 at 6:43
wrapper.find()
returns an array of the results. I guess you should trywrapper.find('[data-test-id="userInfo"]')[0].text()
– Srd Mathur
Nov 20 '18 at 6:47
I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 '18 at 6:53
try withwrapper.find('label#userInfo')
orwrapper.find('#userInfo')
.
– Srd Mathur
Nov 20 '18 at 7:04
TypeError: Cannot read property 'text' of undefined
on both of those :/
– arcade16
Nov 20 '18 at 7:09
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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);
Thanks, but it still fails with the same message.
– arcade16
Nov 20 '18 at 6:43
wrapper.find()
returns an array of the results. I guess you should trywrapper.find('[data-test-id="userInfo"]')[0].text()
– Srd Mathur
Nov 20 '18 at 6:47
I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 '18 at 6:53
try withwrapper.find('label#userInfo')
orwrapper.find('#userInfo')
.
– Srd Mathur
Nov 20 '18 at 7:04
TypeError: Cannot read property 'text' of undefined
on both of those :/
– arcade16
Nov 20 '18 at 7:09
add a comment |
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);
Thanks, but it still fails with the same message.
– arcade16
Nov 20 '18 at 6:43
wrapper.find()
returns an array of the results. I guess you should trywrapper.find('[data-test-id="userInfo"]')[0].text()
– Srd Mathur
Nov 20 '18 at 6:47
I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 '18 at 6:53
try withwrapper.find('label#userInfo')
orwrapper.find('#userInfo')
.
– Srd Mathur
Nov 20 '18 at 7:04
TypeError: Cannot read property 'text' of undefined
on both of those :/
– arcade16
Nov 20 '18 at 7:09
add a comment |
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);
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);
answered Nov 20 '18 at 6:35
Srd MathurSrd Mathur
113
113
Thanks, but it still fails with the same message.
– arcade16
Nov 20 '18 at 6:43
wrapper.find()
returns an array of the results. I guess you should trywrapper.find('[data-test-id="userInfo"]')[0].text()
– Srd Mathur
Nov 20 '18 at 6:47
I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 '18 at 6:53
try withwrapper.find('label#userInfo')
orwrapper.find('#userInfo')
.
– Srd Mathur
Nov 20 '18 at 7:04
TypeError: Cannot read property 'text' of undefined
on both of those :/
– arcade16
Nov 20 '18 at 7:09
add a comment |
Thanks, but it still fails with the same message.
– arcade16
Nov 20 '18 at 6:43
wrapper.find()
returns an array of the results. I guess you should trywrapper.find('[data-test-id="userInfo"]')[0].text()
– Srd Mathur
Nov 20 '18 at 6:47
I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 '18 at 6:53
try withwrapper.find('label#userInfo')
orwrapper.find('#userInfo')
.
– Srd Mathur
Nov 20 '18 at 7:04
TypeError: Cannot read property 'text' of undefined
on both of those :/
– arcade16
Nov 20 '18 at 7:09
Thanks, but it still fails with the same message.
– arcade16
Nov 20 '18 at 6:43
Thanks, but it still fails with the same message.
– arcade16
Nov 20 '18 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 '18 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 '18 at 6:47
I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 '18 at 6:53
I get "TypeError: Cannot read property 'text' of undefined" when trying that
– arcade16
Nov 20 '18 at 6:53
try with
wrapper.find('label#userInfo')
or wrapper.find('#userInfo')
.– Srd Mathur
Nov 20 '18 at 7:04
try with
wrapper.find('label#userInfo')
or wrapper.find('#userInfo')
.– Srd Mathur
Nov 20 '18 at 7:04
TypeError: Cannot read property 'text' of undefined
on both of those :/– arcade16
Nov 20 '18 at 7:09
TypeError: Cannot read property 'text' of undefined
on both of those :/– arcade16
Nov 20 '18 at 7:09
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
What's wrong with current code? I think its correctly checking
– Just code
Nov 20 '18 at 6:24
Post edited to show test failed message
– arcade16
Nov 20 '18 at 6:26