aliaspooryorik
bockensm
02/15/2022, 9:50 PMbeforeeach
in a given-when-then block in TestBox? It does not work like describe/it. I've tried it inside story
and inside given
and neither seem to do the trick.Adam Cameron
<cfscript>
// MyCoolLibrary.cfm
function testMe() {
if (avoidRunningMe()) {
return "one fish"
}
return "two fish"
}
function avoidRunningMe() {
// really slow or is destructive or has external dependencies or something
}
</cfscript>
The library is just included when one wants to use it, eg like this:
describe("Testing MyCoolLibrary", () => {
include "MyCoolLibrary.cfm"
it("checks testMe does the right thing", () => {
// now I need to mock avoidRunningMe before calling testMe...?
})
})
Adam Cameron
beforeAll
/ afterAll
lifecycle events are handled via defining a function of that name, and they run once per test bundle file (https://testbox.ortusbooks.com/in-depth/life-cycle-methods/bdd#beforeall).
In other spec-driven testing frameworks, these lifecycle events are specific to the organisational block they are within; eg each describe
block can have its own beforeAll
handler, just like it can have a beforeEach
handler.
I've verified this on Jasmine, Mocha and RSpec. The docs on Jest are unclear, but I think they work the same way as TestBox.
My own expectations are that TestBox ought to work the same as Jasmine, given TestBox is very very similar to it in many regards. And there's a good argument to be had that RSpec is the one to follow for one's expectations for this style of testing framework.
Thoughts? (also ping @lmajano)lmajano
03/07/2022, 9:11 PMbeforeAll()
and afterAll()
to describe(),story(),feature()
blocksAdam Cameron
ryan
03/22/2022, 8:05 PMAdam Cameron
Adam Cameron
jumpmaster
04/15/2022, 5:48 PMAdam Cameron
it("fails if an exception is thrown", () => {
expect(() => {throw "hi"}).notToThrow()
})
This should fail.
On Lucee 5.3.7.48 it works fine.
On Lucee 5.3.8.206 it doesn't work. IE: this test passes. It also passes if I use toThrow
instead of notToThrow
.
I will try to track it back to a specific change in Lucee, but I suspect something woolly is going on in the TestBox code that makes it fragile.
NB: that is just a distilled-down repro case. My actual case was with an expression that resulted in an exception, and I tried with various other expressions that caused exceptions. All behave the same: toNotThrow
does not work.
Ping @lmajanoAdam Cameron
notToThrow
matcher. Here are some tests:
https://gist.github.com/adamcameron/e1674e216bd8b759fb34e663fc8a6603Adam Cameron
Adam Cameron
Adam Cameron
Adam Cameron
Adam Cameron
Adam Cameron
Adam Cameron
aroundEach
case that I mention therein. https://ortussolutions.atlassian.net/browse/TESTBOX-351aliaspooryorik
Adam Cameron
describe("Tests of testBox's toHaveKey", () => {
it("is a control test", () => {
st = {key="value"}
expect(st).toHaveKey("key") // pass
})
it("handles a key with a null value", () => {
st = {key=javacast("null", "")}
expect(st).toHaveKey("key") // The key(s) [key] does not exist in the target object. Found keys are [[KEY]]
})
it("demonstrates the key does in fact exist", () => {
st = {key=javacast("null", "")}
expect(st.keyArray()).tobe(["key"]) // pass
})
})
Same behaviour in CF and Lucee.
(ping @lmajano)Tim
05/23/2022, 7:54 PMTim
05/23/2022, 7:56 PMStructKeyExists
returns false if the value of the key is null.Tim
05/23/2022, 7:58 PMtoHaveKey
is worth a discussion, but I can see the argument for "`toHaveKey` should return the same thing as keyExists
."Adam Cameron
Adam Cameron
lmajano
05/25/2022, 10:40 PMlmajano
05/25/2022, 10:40 PMstructKeyExists()
is not returninglmajano
05/25/2022, 10:40 PMkeyArray()
and test thatlmajano
05/25/2022, 10:41 PM