I’d like to write a test to check whether my API returns a specific error message
This error message however contains a collection variable
When i run the test, im receiving a syntax error
Example:-
pm.test("Correct error message is returned", function (){
pm.expect(response[0].errorMessage).to.include("Release level: Only use an artist name ((pm.collectionVariables.get("artistName1"))) in a title if it's really part of the title. Do NOT use it just to identify that track is by the artist.")
})
You should be able to see in the editor that the code is incorrect before you send it and get the syntax error.
You can build up the string using the following method.
"Release level: Only use an artist name "+ pm.collectionVariables.get("artistName1") +" in a title if it's really part of the title. Do NOT use it just to identify that track is by the artist."
You can also define the expected result in a variable to help with legibility.
pm.test("Correct error message is returned", function (){
let actualResult = response[0].errorMessage
let expectedResult = "Release level: Only use an artist name "+ pm.collectionVariables.get("artistName1") +" in a title if it's really part of the title. Do NOT use it just to identify that track is by the artist."
pm.expect(actualResult).to.include(expectedResult);
})