Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active April 18, 2022 14:13
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save adamcameron/e1674e216bd8b759fb34e663fc8a6603 to your computer and use it in GitHub Desktop.
Tests for probable bug with notToThrow assertion.
import test.BaseSpec
component extends=BaseSpec {
function run() {
describe("Tests TestBox assertions", () => {
describe("Tests toThrow", () => {
it("should pass because it DOES throw an exception with the matching message", () => {
expect(() => throwExceptionWithMatchingMessage()).toThrow(regex="^.*MATCH_THIS.*$")
})
})
describe("Tests notToThrow", () => {
it("should pass because it is throwing a different exception", () => {
expect(() => throwDifferentException()).notToThrow(regex="^.*MATCH_THIS.*$")
})
it("should fail because it DOES throw an exception with the matching message", () => {
expect(() => throwExceptionWithMatchingMessage()).notToThrow(regex="^.*MATCH_THIS.*$")
})
it("should fail because it DOES throw an exception with the matching detail", () => {
expect(() => throwExceptionWithMatchingDetail()).notToThrow(regex="^.*MATCH_THIS.*$")
})
it("should fail because it DOES throw an exception that matches on both message and detail", () => {
expect(() => throwExceptionWithMatchingMessageAndDetail()).notToThrow(regex="^.*MATCH_THIS.*$")
})
})
})
}
function throwExceptionWithMatchingMessage() {
throw(message="MESSAGE_MATCH_THIS")
}
function throwExceptionWithMatchingDetail() {
throw(detail="DETAIL_MATCH_THIS")
}
function throwExceptionWithMatchingMessageAndDetail() {
throw(message="BOTH_MATCH_THIS", detail="BOTH_MATCH_THIS")
}
function throwDifferentException() {
throw(message="DIFFERENT_MESSAGE", detail="DETAIL_MATCH_THIS")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment