A test against a string passes regardless of the value
This test pm.expect(jsonData.payload.invitationStatus == "A");
works regardless of the value that invitationStatus
actually contains.
i.e. payload.invitationStatus = E
will pass in the test.
How do I get this to pass only if the value is A?
Here are a couple of examples of the payload:
{
"payload": {
"buyer": "",
"error": "E",
"invitationStatus": "E",
"supplier": "",
"terms": ""
}
}
{
"payload": {
"buyer": "omitted omitted",
"error": "S",
"invitationStatus": "A",
"supplier": "ABC Supplier",
"terms": ""
}
}
Here's the test itself:
// Setters
let jsonData = JSON.parse(responseBody);
// Testers
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Invitation status is A", function () {
if(jsonData.payload) {
pm.expect(jsonData.payload.invitationStatus == "A");
} else {
throw new Error("Unexpected structure");
}
});
postman newman
add a comment |
This test pm.expect(jsonData.payload.invitationStatus == "A");
works regardless of the value that invitationStatus
actually contains.
i.e. payload.invitationStatus = E
will pass in the test.
How do I get this to pass only if the value is A?
Here are a couple of examples of the payload:
{
"payload": {
"buyer": "",
"error": "E",
"invitationStatus": "E",
"supplier": "",
"terms": ""
}
}
{
"payload": {
"buyer": "omitted omitted",
"error": "S",
"invitationStatus": "A",
"supplier": "ABC Supplier",
"terms": ""
}
}
Here's the test itself:
// Setters
let jsonData = JSON.parse(responseBody);
// Testers
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Invitation status is A", function () {
if(jsonData.payload) {
pm.expect(jsonData.payload.invitationStatus == "A");
} else {
throw new Error("Unexpected structure");
}
});
postman newman
Your first line of your code in this question shows a comparison between values. Your test is showing a value declaration, not a comparison.pm.expect(jsonData.payload.invitationStatus = "A");
in that instance it does not matter what the value is as the invitation status is declared as "A" in the test, thus no matter what value is set, it will be reset when the test is run.
– ViaTech
Nov 23 '18 at 0:23
@ViaTech I tried===
,==
and=
all of which passed regardless of the value. I updated the question.
– Naguib Ihab
Nov 23 '18 at 0:25
ah okay looked simple enough, guess not. I'm also guessing you tested the value ofpayload.invitationStatus
in thejsonData.payload
conditional. Is that set correctly as the value you want?
– ViaTech
Nov 23 '18 at 0:29
@ViaTech sorry I don't get what you're asking
– Naguib Ihab
Nov 23 '18 at 0:36
add a comment |
This test pm.expect(jsonData.payload.invitationStatus == "A");
works regardless of the value that invitationStatus
actually contains.
i.e. payload.invitationStatus = E
will pass in the test.
How do I get this to pass only if the value is A?
Here are a couple of examples of the payload:
{
"payload": {
"buyer": "",
"error": "E",
"invitationStatus": "E",
"supplier": "",
"terms": ""
}
}
{
"payload": {
"buyer": "omitted omitted",
"error": "S",
"invitationStatus": "A",
"supplier": "ABC Supplier",
"terms": ""
}
}
Here's the test itself:
// Setters
let jsonData = JSON.parse(responseBody);
// Testers
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Invitation status is A", function () {
if(jsonData.payload) {
pm.expect(jsonData.payload.invitationStatus == "A");
} else {
throw new Error("Unexpected structure");
}
});
postman newman
This test pm.expect(jsonData.payload.invitationStatus == "A");
works regardless of the value that invitationStatus
actually contains.
i.e. payload.invitationStatus = E
will pass in the test.
How do I get this to pass only if the value is A?
Here are a couple of examples of the payload:
{
"payload": {
"buyer": "",
"error": "E",
"invitationStatus": "E",
"supplier": "",
"terms": ""
}
}
{
"payload": {
"buyer": "omitted omitted",
"error": "S",
"invitationStatus": "A",
"supplier": "ABC Supplier",
"terms": ""
}
}
Here's the test itself:
// Setters
let jsonData = JSON.parse(responseBody);
// Testers
pm.test("Status code is 200", function () {
pm.response.to.have.status(200);
});
pm.test("Invitation status is A", function () {
if(jsonData.payload) {
pm.expect(jsonData.payload.invitationStatus == "A");
} else {
throw new Error("Unexpected structure");
}
});
postman newman
postman newman
edited Nov 23 '18 at 0:24
Naguib Ihab
asked Nov 23 '18 at 0:07
Naguib IhabNaguib Ihab
1,6091740
1,6091740
Your first line of your code in this question shows a comparison between values. Your test is showing a value declaration, not a comparison.pm.expect(jsonData.payload.invitationStatus = "A");
in that instance it does not matter what the value is as the invitation status is declared as "A" in the test, thus no matter what value is set, it will be reset when the test is run.
– ViaTech
Nov 23 '18 at 0:23
@ViaTech I tried===
,==
and=
all of which passed regardless of the value. I updated the question.
– Naguib Ihab
Nov 23 '18 at 0:25
ah okay looked simple enough, guess not. I'm also guessing you tested the value ofpayload.invitationStatus
in thejsonData.payload
conditional. Is that set correctly as the value you want?
– ViaTech
Nov 23 '18 at 0:29
@ViaTech sorry I don't get what you're asking
– Naguib Ihab
Nov 23 '18 at 0:36
add a comment |
Your first line of your code in this question shows a comparison between values. Your test is showing a value declaration, not a comparison.pm.expect(jsonData.payload.invitationStatus = "A");
in that instance it does not matter what the value is as the invitation status is declared as "A" in the test, thus no matter what value is set, it will be reset when the test is run.
– ViaTech
Nov 23 '18 at 0:23
@ViaTech I tried===
,==
and=
all of which passed regardless of the value. I updated the question.
– Naguib Ihab
Nov 23 '18 at 0:25
ah okay looked simple enough, guess not. I'm also guessing you tested the value ofpayload.invitationStatus
in thejsonData.payload
conditional. Is that set correctly as the value you want?
– ViaTech
Nov 23 '18 at 0:29
@ViaTech sorry I don't get what you're asking
– Naguib Ihab
Nov 23 '18 at 0:36
Your first line of your code in this question shows a comparison between values. Your test is showing a value declaration, not a comparison.
pm.expect(jsonData.payload.invitationStatus = "A");
in that instance it does not matter what the value is as the invitation status is declared as "A" in the test, thus no matter what value is set, it will be reset when the test is run.– ViaTech
Nov 23 '18 at 0:23
Your first line of your code in this question shows a comparison between values. Your test is showing a value declaration, not a comparison.
pm.expect(jsonData.payload.invitationStatus = "A");
in that instance it does not matter what the value is as the invitation status is declared as "A" in the test, thus no matter what value is set, it will be reset when the test is run.– ViaTech
Nov 23 '18 at 0:23
@ViaTech I tried
===
, ==
and =
all of which passed regardless of the value. I updated the question.– Naguib Ihab
Nov 23 '18 at 0:25
@ViaTech I tried
===
, ==
and =
all of which passed regardless of the value. I updated the question.– Naguib Ihab
Nov 23 '18 at 0:25
ah okay looked simple enough, guess not. I'm also guessing you tested the value of
payload.invitationStatus
in the jsonData.payload
conditional. Is that set correctly as the value you want?– ViaTech
Nov 23 '18 at 0:29
ah okay looked simple enough, guess not. I'm also guessing you tested the value of
payload.invitationStatus
in the jsonData.payload
conditional. Is that set correctly as the value you want?– ViaTech
Nov 23 '18 at 0:29
@ViaTech sorry I don't get what you're asking
– Naguib Ihab
Nov 23 '18 at 0:36
@ViaTech sorry I don't get what you're asking
– Naguib Ihab
Nov 23 '18 at 0:36
add a comment |
1 Answer
1
active
oldest
votes
I'm not sure why the ==
didn't work but this worked pm.expect(jsonData.payload.invitationStatus).to.eql("A");
Here's a good resource for other postman tests examples https://www.getpostman.com/docs/v6/postman/scripts/test_examples
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%2f53439281%2fa-test-against-a-string-passes-regardless-of-the-value%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
I'm not sure why the ==
didn't work but this worked pm.expect(jsonData.payload.invitationStatus).to.eql("A");
Here's a good resource for other postman tests examples https://www.getpostman.com/docs/v6/postman/scripts/test_examples
add a comment |
I'm not sure why the ==
didn't work but this worked pm.expect(jsonData.payload.invitationStatus).to.eql("A");
Here's a good resource for other postman tests examples https://www.getpostman.com/docs/v6/postman/scripts/test_examples
add a comment |
I'm not sure why the ==
didn't work but this worked pm.expect(jsonData.payload.invitationStatus).to.eql("A");
Here's a good resource for other postman tests examples https://www.getpostman.com/docs/v6/postman/scripts/test_examples
I'm not sure why the ==
didn't work but this worked pm.expect(jsonData.payload.invitationStatus).to.eql("A");
Here's a good resource for other postman tests examples https://www.getpostman.com/docs/v6/postman/scripts/test_examples
answered Nov 23 '18 at 0:48
Naguib IhabNaguib Ihab
1,6091740
1,6091740
add a comment |
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%2f53439281%2fa-test-against-a-string-passes-regardless-of-the-value%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
Your first line of your code in this question shows a comparison between values. Your test is showing a value declaration, not a comparison.
pm.expect(jsonData.payload.invitationStatus = "A");
in that instance it does not matter what the value is as the invitation status is declared as "A" in the test, thus no matter what value is set, it will be reset when the test is run.– ViaTech
Nov 23 '18 at 0:23
@ViaTech I tried
===
,==
and=
all of which passed regardless of the value. I updated the question.– Naguib Ihab
Nov 23 '18 at 0:25
ah okay looked simple enough, guess not. I'm also guessing you tested the value of
payload.invitationStatus
in thejsonData.payload
conditional. Is that set correctly as the value you want?– ViaTech
Nov 23 '18 at 0:29
@ViaTech sorry I don't get what you're asking
– Naguib Ihab
Nov 23 '18 at 0:36