This is the code for the failing test. (In the tests tab for the submit request).
pm.test("Scripts added correctly", () => {
let xkcdRequest = collection.item[0].item.find(req => { return req.name === "xkcd"})
let prereq = xkcdRequest.event.find(event => { return event.listen === "prerequest"})
pm.expect(prereq.listen, 'check prerequest script').equals("prerequest")
let test = xkcdRequest.event.find(event => { return event.listen === "test" })
pm.expect(test.listen, 'check test script').equals("test")
pm.expect(test.script.exec.toString(), 'check test script syntax').to.include("postman.setNextRequest(null)", "pm.test")
pass += 1
})
In particular, its this assertion that is currently failing.
pm.expect(test.script.exec.toString(), 'check test script syntax').to.include("postman.setNextRequest(null)", "pm.test")
This line is finding the request in the collection.
let xkcdRequest = collection.item[0].item.find(req => { return req.name === "xkcd"})
This is returning the test event within the collection (aka Test tab).
let test = xkcdRequest.event.find(event => { return event.listen === "test" })
Itās a bit more than just the code in the tests tab at this point, but this part of the assertion will return all of the code you have in the tests tab as a string and the test is simply testing that somewhere in the code it contains the text āpostman.setNextRequest(null)ā and āpm.testā.
test.script.exec.toString()
My recommendation would be to clone the submit request, and then edit the test to console log the above variable just before it does the assertion to see what its returning. As it doesnāt seem to be returning the tests tab, but something else. It looks like its returning an array of some sort.
let test = xkcdRequest.event.find(event => { return event.listen === "test" })
pm.expect(test.listen, 'check test script').equals("test")
console.log(test.script.exec.toString());
pm.expect(test.script.exec.toString(), 'check test script syntax').to.include("postman.setNextRequest(null)", "pm.test")