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
salesforce lightning
add a comment |
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
salesforce lightning
Took comments and explanation out of the code block so they would be clearer and easier to find.
– Dave
Nov 26 '18 at 11:05
add a comment |
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
salesforce lightning
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
salesforce lightning
salesforce lightning
edited Nov 26 '18 at 11:05
Dave
2,84681830
2,84681830
asked Nov 26 '18 at 9:32
Varun KumarVarun Kumar
61
61
Took comments and explanation out of the code block so they would be clearer and easier to find.
– Dave
Nov 26 '18 at 11:05
add a comment |
Took comments and explanation out of the code block so they would be clearer and easier to find.
– Dave
Nov 26 '18 at 11:05
Took comments and explanation out of the code block so they would be clearer and easier to find.
– Dave
Nov 26 '18 at 11:05
Took comments and explanation out of the code block so they would be clearer and easier to find.
– Dave
Nov 26 '18 at 11:05
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478159%2fhow-to-test-component-events-when-event-and-handler-are-in-different-components%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53478159%2fhow-to-test-component-events-when-event-and-handler-are-in-different-components%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Took comments and explanation out of the code block so they would be clearer and easier to find.
– Dave
Nov 26 '18 at 11:05