Skip to content

Instantly share code, notes, and snippets.

@adamcameron
Last active May 19, 2022 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adamcameron/332e3cda31fa933cfe3a783be07bc59e to your computer and use it in GitHub Desktop.
Save adamcameron/332e3cda31fa933cfe3a783be07bc59e to your computer and use it in GitHub Desktop.
TTF tests for misc functions that don't fit another category
<cfscript>
void function run() {
describe("Tests of it", () => {
it("prefixes its message with ""It""", () => {
savecontent variable="message" {
it("IS A TEST MESSAGE", () => {})
}
tinyTest.results.pass--
expect(message).toInclude("It IS A TEST MESSAGE")
})
})
describe("Tests of expect", () => {
it("exists", () => {
expect("NOT_TESTED")
})
it("returns a struct with keys for matcher callbacks", () => {
var result = expect("NOT_TESTED")
if (isNull(result) || isNull(result.toBe) || !isCustomFunction(local.result.toBe)) {
throw(type="TinyTest.TestFailedException")
}
})
})
describe("Tests of fail", () => {
it("fails a test", (type) => {
try {
fail()
} catch (TinyTest.FailureException e) {
// OK
} catch (any e) {
throw(type="TinyTest.TestFailedException")
}
})
})
describe("Test of test result visualisations", () => {
it("specifies that a pass should have positive emphasis", () => {
savecontent variable="message" {
it("is a passing test", () => {
expect(true).toBeTrue()
})
}
expect(message).toInclude('is a passing test: <span class="pass">OK</span>')
})
it("specifies that a fail should have negative emphasis", () => {
savecontent variable="message" {
it("is a failing test", () => {
expect(false).toBeTrue()
})
}
expect(message).toInclude('is a failing test: <span class="fail"><em>Failed</em></span>')
})
it("specifies that an error should have more emphasis than a fail", () => {
savecontent variable="message" {
it("is an erroring test", () => {
throw(type="", message="TEST_EXCEPTION", detail="TEST_EXCEPTION_DETAIL")
})
}
expect(message).toInclude('is an erroring test: <span class="error"><strong>Error: [TEST_EXCEPTION][TEST_EXCEPTION_DETAIL]</strong></span>')
})
tinyTest.results.pass--
tinyTest.results.fail--
tinyTest.results.error--
})
}
tinyTest.runTests()
</cfscript>
@adamcameron
Copy link
Author

Where do you run the code on?

It's called from this one: https://gist.github.com/adamcameron/838b30252bb0a390bdf324a8ab10b753, which I run via trycf.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment