[Testbox 4.2.0] How Can I Instantiate Modules in Unit Tests?

Happy Holidays CFers. :slight_smile:

I’m building out some unit tests for a model, and I’d like to be able to leverage CBValidation to make sure the model will pass validation checks when the proper data is added and will fail when something is missing.

However, I’m not sure how to inject CBValidation, which is already installed and in use in the main app. When I try calling:

var validationManager = application.wirebox.getInstance( “ValidationManager@cbvalidation” );

I get the error, “Requested instance not found: ‘ValidationManager@cbvalidation’”

Here’s what my unit test component looks like:

component extends=“coldbox.system.testing.BaseModelTest” model=“models.quote.Quote” {

variables.validData = {
// … test data
};

/*********************************** LIFE CYCLE Methods ***********************************/

function beforeAll(){
super.beforeAll();

// setup the model
super.setup();

// init the model object
model.init();

}

function afterAll(){
super.afterAll();
}

/*********************************** BDD SUITES ***********************************/

function run(){

describe( “A Quote”, function(){

it( “can be created”, function(){
expect( model ).toBeComponent();
});

it( “will validate when given proper data”, function() {

var validationManager = application.wirebox.getInstance( “ValidationManager@cbvalidation” );

var quote = application.wirebox
.getObjectPopulator()
.populateFromStruct(
target = model,
memento = validData
)
;

var validationResult = validationManager.validate( quote );

debug( validationResult );

} );

});

}

}

Any help or insight that you share would be very helpful!