← ClaudeAtlas

coldbox-testing-interceptorlisted

Use this skill when unit testing ColdBox interceptors in isolation using BaseInterceptorTest, accessing the pre-wired interceptor variable, leveraging mock helpers (mockController, mockRequestService, mockLogger, mockLogBox, mockFlash), configuring interceptor properties with configProperties, calling interceptor announce points directly, or scaffolding interceptor tests with CommandBox.
ColdBox/skills · ★ 0 · Testing & QA · score 61
Install: claude install-skill ColdBox/skills
# Interceptor Unit Testing in ColdBox ## When to Use This Skill - Unit testing an interceptor CFC in complete isolation (no virtual ColdBox app) - Testing individual interception points (`preProcess`, `postProcess`, `onException`, custom events) - Mocking the controller, request service, logger, or flash scope - Verifying that an interceptor modifies the request context or calls other services --- ## Base Class ```boxlang coldbox.system.testing.BaseInterceptorTest ``` Extends `BaseTestCase` with `loadColdBox="false"`. Your interceptor CFC is instantiated and handed to you in `variables.interceptor`. --- ## Minimal Setup ```boxlang class extends="coldbox.system.testing.BaseInterceptorTest" interceptor="interceptors.SecurityFirewall" { function beforeAll() { super.setup() // creates variables.interceptor and all mock helpers } function run() { describe( "SecurityFirewall", () => { it( "allows authenticated requests through", () => { // inject a mock authenticated session into the mocked request context mockRequestContext.$( "getValue" ).$results( { userId: 42 } ) interceptor.preProcess( mockRequestContext, {} ) expect( mockRequestContext.$never( "noRender" ) ).toBeTrue() } ) } ) } } ``` --- ## Pre-Wired Mock Variables After `super.setup()`, the following are available: | Variable | Description | |---|---| | `variables.intercept