Brent
07/02/2024, 8:39 PMsetSomeProp()
method that exists on it?bdw429s
07/02/2024, 8:46 PMbdw429s
07/02/2024, 8:47 PMstructKeyExists()
paired with the isCustomFunction()
BIFbdw429s
07/02/2024, 8:47 PMstructKeyExists( myCFC, "myMethod" ) && isCustomFunction( myCFC.myMethod )
bdw429s
07/02/2024, 8:47 PMbdw429s
07/02/2024, 8:48 PMTim
07/02/2024, 8:50 PMexpect(() -> setSomeProp()).notToThrow()
Brent
07/02/2024, 8:51 PMBrent
07/02/2024, 8:57 PMstructkeyexists
passes, but calling the method on the model with .nottothrow()
fails with: The incoming function DID throw an exception of type [expression] with message [The function [target] does not exist on the Object,only the following functions are available: ...
Odd thing is other assertions calling the same methods pass 😕Tim
07/02/2024, 9:02 PMbdw429s
07/02/2024, 9:04 PMbdw429s
07/02/2024, 9:04 PMBrent
07/02/2024, 9:08 PMBrent
07/02/2024, 9:20 PMit("should have all the right props on the model", () => {
local.model = createObject("component", "path.to.my.model");
expect(structKeyExists(local.model, "setSomeProp")).toBeTrue(); // passes
expect(local.model.setSomeProp(someArg)).notToThrow(); // fails
});
And the model.cfc under test:
component output="false" extends="user" accessors="true" {
property name="otherUserModel";
property name="otherMetaData";
this.otherUserModel = createObject("component", "otherUserModel");
this.otherMetaData = getComponentMetadata(this.otherUserModel);
for (variables.p in this.otherMetaData.properties) {
this[variables.p] = this.otherUserModel[variables.p.name];
}
for (variables.f in this.otherMetaData.functions) {
this[variables.f] = this.otherUserModel[variables.f.name];
}
this.otherUserModel.initProps(this);
}
For fuller context, the otherUserModel
that the above model creates:
// OtherUserModel.cfc
component output="false" extends="user" accessors="true" {
property name="someProp" type="string" getter="true" setter="true";
// other props...
public void function initProps(theModel) {
theModel.setSomeProp("someval");
// other prop setters etc...
}
this.initProps(this);
}
Tim
07/02/2024, 9:21 PMBrent
07/02/2024, 9:21 PMTim
07/02/2024, 9:21 PM() ->
part in my example is important.Tim
07/02/2024, 9:23 PM=>
?Brent
07/02/2024, 9:23 PMlocal.model
. I'm still learning about scoping in CFML, I guess I need to use var model at the outer scope I'm assumingBrent
07/02/2024, 9:24 PMvar model = ...
at the top scope in the test it()
block and it all passes. thank youBrent
07/02/2024, 9:25 PMAdam Cameron
Using testbox to test a component, is there a way to assert that a component has a method?
#QuestionBeggingAlert Why are you thinking this is something you need to test for? What's the test case? eg: "it does x when y"? Method-existence is generally an implementation detail, so not something one would test for
Brent
07/02/2024, 10:52 PM