Skip to content

Commit

Permalink
Throw WireActionNotFound Exception for Non-Existent Listener Actions #…
Browse files Browse the repository at this point in the history
  • Loading branch information
grantcopley committed Jan 10, 2024
1 parent 2669d65 commit 3329c17
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
6 changes: 6 additions & 0 deletions models/renderer/BaseRenderer.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,12 @@ component accessors="true" {
if ( structKeyExists( listeners, eventName ) ) {
var listener = listeners[ eventName ];

if ( !hasMethod( listener ) ){
throw(
type = "WireActionNotFound",
message = "Wire action '" & listener & "' not found on your component."
);
}
if ( len( arguments.eventName ) && hasMethod( listener ) ) {
return invokeMethod( methodName = listener, passThroughParameters = arguments.parameters );
}
Expand Down
21 changes: 18 additions & 3 deletions test-harness/tests/specs/CBWIRESpec.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,15 @@ component extends="coldbox.system.testing.BaseTestCase" {
var result = renderInitial( comp );
var initialDataJSON = parseInitialData( result );
var initialDataStruct = deserializeJSON( initialDataJSON );
expect( initialDataStruct.effects.listeners[ 1] ).toBe( "onSuccess" );
expect( initialDataStruct.effects.listeners.findNoCase( "onSuccess" ) ).toBeTrue();
} );

it( "wire:initial-data has expected structure", function() {
comp.$( "getComponentTemplatePath", "/tests/templates/dataproperty.cfm" );
var result = renderInitial( comp );
var initialDataJSON = parseInitialData( result );
var initialDataStruct = deserializeJSON( initialDataJSON );
expect( initialDataStruct.effects.listeners[ 1 ] ).toBe( "onSuccess" );
expect( initialDataStruct.effects.listeners.findNoCase( "onSuccess" ) ).toBeTrue();
expect( initialDataStruct.serverMemo.data.mounted ).toBeTrue();
expect( initialDataStruct.serverMemo.data.name ).toBe( "Grant" );
expect( structKeyExists( initialDataStruct.serverMemo, "checksum" ) ).toBeTrue();
Expand Down Expand Up @@ -175,7 +175,7 @@ component extends="coldbox.system.testing.BaseTestCase" {
var result = renderInitial( comp );
var initialDataJSON = parseInitialData( result );
var initialDataStruct = deserializeJSON( initialDataJSON );
expect( initialDataStruct.effects.listeners[ 1 ] ).toBe( "onSuccess" );
expect( initialDataStruct.effects.listeners.findNoCase( "onSuccess") ).toBeTrue();
} );

it( "can use property injection on component", function() {
Expand Down Expand Up @@ -748,6 +748,21 @@ component extends="coldbox.system.testing.BaseTestCase" {
var result = renderSubsequent( comp );
expect( result.effects.html ).toContain( "listener: true" );
} );

it( "throws error when executing a listener with a missing action", function() {
rc.updates = [ {
type: "FireEvent",
payload: {
event: "missingAction",
params: []
}
} ];
comp.$( "getComponentTemplatePath", "/tests/templates/dataproperty.cfm" );
expect( function() {
var result = renderSubsequent( comp );
} ).toThrow( type="WireActionNotFound" );
} );

} );


Expand Down
3 changes: 2 additions & 1 deletion test-harness/tests/templates/TestComponent.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ component extends="cbwire.models.Component" {
queryString = [ "name" ];

listeners = {
"onSuccess": "someMethod"
"onSuccess": "someMethod",
"missingAction": "actionDoesNotExists"
};

data = {
Expand Down

0 comments on commit 3329c17

Please sign in to comment.