The $T global function provides a utility method called $T.fireApplicationEvent to fire an event when testing components that handle the application event.
The code snippet to fire an application event from the testing service is as follows:
$T.fireApplicationEvent(eventName, eventParams)
The following is a sample code snippet that shows how to test a component that handles the application event:
describe('c:componentsubscribingToAppEvent', function () {
it('verify application event', function (done) {
$T.createComponent("c:componentsubscribingToAppEvent")
.then(function (component) {
$T.fireApplicationEvent("c:applicationEvent", {"eventData": "sample event Data"});
expect(component.get("v.eventDataCaptured")).toBe("sample event Data");
done();
}).catch(function (e) {
done.fail(e);
});
});
});
The $T utility function provides other methods, and you can explore the code in the open source repository at https://github.com/forcedotcom/LightningTestingService/blob/master/Lightning-component-tests/test/default/staticresources/lts_testutil.resource.
Also, for more advanced use cases, such as testing for Lightning Data Services, you can refer to the sample code provided in the repository at https://github.com/forcedotcom/LightningTestingService/blob/master/Lightning-component-tests/test/default/staticresources/jasmineLightningDataServiceTests.resource.