function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Varun kumar SaxenaVarun kumar Saxena 

How to test component events when event and handler are in different components?

In the reference jasmine test resource, component event(egComponentEvent) registration and handler is done in same component(egEventHandling).
Thus, we are able to test the result after event is fired.
https://github.com/forcedotcom/LightningTestingService/blob/master/lightning-component-tests/test/default/staticresources/jasmineExampleTests.resource
/**
     * Component under test: 'c:egEventHandling'
     * This spec shows how to validate a component's handling of component- and
     * application-level events.
     */
    describe('c:egEventHandling', function() {
        it('handles component- and application-level events', function(done) {
            $T.createComponent("c:egEventHandling", null)
            .then(function(component){
                var cmpEvent = component.getEvent("sampleEvent");
                cmpEvent.setParams({"data":"component event fired"});
                cmpEvent.fire()
                expect(component.get("v.message")).toBe("component event fired");
                $T.fireApplicationEvent("c:egApplicationEvent", {"data":"application event fired"});
                expect(component.get("v.message")).toBe("application event fired");
                done();
            }).catch(function(e) {
                done.fail(e);
            });
        });
    });
Facing issue to test the results after component event is fired, when event registration and its handler is done in different components.
We are firing a component level  event in component 1 and the handler is being invoked in Component 2 ,
We are struggling in testing component event where as component is getting fired but we are not able to see the handler invoked in the Component 2
Kindly help us in getting the correct solution for the below code
 $T.createComponent("c:tagr_Tag",attributes,true)
  .then(function(component) {
  var evt = component.getEvent('componentEvent');
  evt.setParam('entity', entity); 
  evt.fire();
expect(evt.fire()).tobe.(true);
}
Here event is getting fired from tagr_Tag but handler is not getting invoked from different component.
Please help us in arriving to the solution using any approach like spyon or something else.
Thanks in Advance