0

Hi I have a following code, Which i need to change the window location in using button and link.

export default class CampaignAdSection extends Component {
  constructor(props) {
    super(props)
    this.customiseClickable = this.customiseClickable.bind(this);
  }
  customiseClickable(e) {
    this.props.history.push(`/customize/aus`);
  }

  render() {
    let { packages, history, campaignDetails } = this.props;
    return (
     <div className="xs-text-center">
          <button
            type="button"
            className="btn btn-primary pkg-adbtn"
            onClick={e => this.customiseClickable(e)}
          >
            Trip
          </button>{' '}
          <b className="color-grey-secondary">
            {' '}
            or,{' '}
            <Link
              to={
                `${
                  history.location.pathname.indexOf('request-callback') > 0
                    ? history.location.pathname.split('request-callback')[0]
                    : history.location.pathname + '/'
                }request-callback` +
                `${history.location.search ? history.location.search : ''}`
              }
              className="tracker-talkbtn"
            >
              Expert
            </Link>
          </b>
        </div>

    );
  }
}

Based on my code it has been working. But how can i add the spec for this? i am the beginner for react test. Can you please give some idea about this?

i want to click that button and check whether location has been changed or not?

skyboyer
  • 22,209
  • 7
  • 57
  • 64
Akbar Basha
  • 1,168
  • 1
  • 16
  • 38

1 Answers1

-1

You can simulate a Button Click for testing reasons with using Jest.

Check out this to find out how: Simulate a button click in Jest

Sarah
  • 72
  • 10
  • Hi i can able to trigger the button click but it thrown the following error, `VM2313:1 Uncaught TypeError: this.props.history.push is not a function` while running in browser it's working fine but when i try to check in test case(node) it shows that error. So i can't abel to test – Akbar Basha Oct 22 '18 at 13:26
  • Nobody said "using enzyme" – monokrome Jan 11 '21 at 23:54