onBlur is not getting called in Jest Test Cases , React App
up vote
2
down vote
favorite
I have a component where I have written onBlur and onChange event handlers on an input type=text.
<input type="text" onBlur={ this.fetchProspectIdDetails } onChange={ this.handleProspectIdChange } name="prospectId" value={this.state.prospectId}></input>
When I am trying to write test cases for onchange it works
it('Testing empty Salesforce Id Check', () => {
wrapper.find('input[name="prospectId"]')
.simulate('change', {target: {name: 'prospectId', value: ''}});
expect(wrapper.state('validSalesForceId')).toEqual(false);
});
But onBlur function i.e. fetchProspectIdDetails is not being called
it('Testing the ProspectId State', () => {
wrapper.find('input[name="prospectId"]')
.simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});
expect(wrapper.state('prospectId')).toEqual('001G000000mIQIY');
});
What am I doing wrong ?
javascript reactjs jasmine jestjs enzyme
add a comment |
up vote
2
down vote
favorite
I have a component where I have written onBlur and onChange event handlers on an input type=text.
<input type="text" onBlur={ this.fetchProspectIdDetails } onChange={ this.handleProspectIdChange } name="prospectId" value={this.state.prospectId}></input>
When I am trying to write test cases for onchange it works
it('Testing empty Salesforce Id Check', () => {
wrapper.find('input[name="prospectId"]')
.simulate('change', {target: {name: 'prospectId', value: ''}});
expect(wrapper.state('validSalesForceId')).toEqual(false);
});
But onBlur function i.e. fetchProspectIdDetails is not being called
it('Testing the ProspectId State', () => {
wrapper.find('input[name="prospectId"]')
.simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});
expect(wrapper.state('prospectId')).toEqual('001G000000mIQIY');
});
What am I doing wrong ?
javascript reactjs jasmine jestjs enzyme
1
Probably that you are simuating change instead of blurwrapper.find('input[name="prospectId"]').simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});
– Shubham Khatri
Nov 21 at 7:22
By mistake i have written change here in the blur test case. In the actual i have written blur , but it has not been called. I will edit the question, to correct that mistake.
– Atul kumar singh
Nov 21 at 7:28
@Atulkumarsingh can you share the code forfetchProspectIdDetails?
– brian-lives-outdoors
Nov 22 at 2:59
add a comment |
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I have a component where I have written onBlur and onChange event handlers on an input type=text.
<input type="text" onBlur={ this.fetchProspectIdDetails } onChange={ this.handleProspectIdChange } name="prospectId" value={this.state.prospectId}></input>
When I am trying to write test cases for onchange it works
it('Testing empty Salesforce Id Check', () => {
wrapper.find('input[name="prospectId"]')
.simulate('change', {target: {name: 'prospectId', value: ''}});
expect(wrapper.state('validSalesForceId')).toEqual(false);
});
But onBlur function i.e. fetchProspectIdDetails is not being called
it('Testing the ProspectId State', () => {
wrapper.find('input[name="prospectId"]')
.simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});
expect(wrapper.state('prospectId')).toEqual('001G000000mIQIY');
});
What am I doing wrong ?
javascript reactjs jasmine jestjs enzyme
I have a component where I have written onBlur and onChange event handlers on an input type=text.
<input type="text" onBlur={ this.fetchProspectIdDetails } onChange={ this.handleProspectIdChange } name="prospectId" value={this.state.prospectId}></input>
When I am trying to write test cases for onchange it works
it('Testing empty Salesforce Id Check', () => {
wrapper.find('input[name="prospectId"]')
.simulate('change', {target: {name: 'prospectId', value: ''}});
expect(wrapper.state('validSalesForceId')).toEqual(false);
});
But onBlur function i.e. fetchProspectIdDetails is not being called
it('Testing the ProspectId State', () => {
wrapper.find('input[name="prospectId"]')
.simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});
expect(wrapper.state('prospectId')).toEqual('001G000000mIQIY');
});
What am I doing wrong ?
javascript reactjs jasmine jestjs enzyme
javascript reactjs jasmine jestjs enzyme
edited Nov 21 at 7:29
asked Nov 21 at 7:20
Atul kumar singh
109214
109214
1
Probably that you are simuating change instead of blurwrapper.find('input[name="prospectId"]').simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});
– Shubham Khatri
Nov 21 at 7:22
By mistake i have written change here in the blur test case. In the actual i have written blur , but it has not been called. I will edit the question, to correct that mistake.
– Atul kumar singh
Nov 21 at 7:28
@Atulkumarsingh can you share the code forfetchProspectIdDetails?
– brian-lives-outdoors
Nov 22 at 2:59
add a comment |
1
Probably that you are simuating change instead of blurwrapper.find('input[name="prospectId"]').simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});
– Shubham Khatri
Nov 21 at 7:22
By mistake i have written change here in the blur test case. In the actual i have written blur , but it has not been called. I will edit the question, to correct that mistake.
– Atul kumar singh
Nov 21 at 7:28
@Atulkumarsingh can you share the code forfetchProspectIdDetails?
– brian-lives-outdoors
Nov 22 at 2:59
1
1
Probably that you are simuating change instead of blur
wrapper.find('input[name="prospectId"]').simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});– Shubham Khatri
Nov 21 at 7:22
Probably that you are simuating change instead of blur
wrapper.find('input[name="prospectId"]').simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});– Shubham Khatri
Nov 21 at 7:22
By mistake i have written change here in the blur test case. In the actual i have written blur , but it has not been called. I will edit the question, to correct that mistake.
– Atul kumar singh
Nov 21 at 7:28
By mistake i have written change here in the blur test case. In the actual i have written blur , but it has not been called. I will edit the question, to correct that mistake.
– Atul kumar singh
Nov 21 at 7:28
@Atulkumarsingh can you share the code for
fetchProspectIdDetails?– brian-lives-outdoors
Nov 22 at 2:59
@Atulkumarsingh can you share the code for
fetchProspectIdDetails?– brian-lives-outdoors
Nov 22 at 2:59
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
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%2f53407041%2fonblur-is-not-getting-called-in-jest-test-cases-react-app%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
1
Probably that you are simuating change instead of blur
wrapper.find('input[name="prospectId"]').simulate('blur', {target: {name: 'prospectId', value: '001G000000mIQIY'}});– Shubham Khatri
Nov 21 at 7:22
By mistake i have written change here in the blur test case. In the actual i have written blur , but it has not been called. I will edit the question, to correct that mistake.
– Atul kumar singh
Nov 21 at 7:28
@Atulkumarsingh can you share the code for
fetchProspectIdDetails?– brian-lives-outdoors
Nov 22 at 2:59