score:0

try to bind your this.submitchoice() function in the constructor.

this.submitchoice = this.submitchoice.bind(this)

score:0

you are not binding your function to onclick event, you are calling it and since it return nothing you are basically binding undefined to onclick.

this:

onclick={this.submitchoice(this.state.imageurls[0])} 

is same as this:

onclick-{undefined}

because

console.log(this.submitchoice(this.state.imageurls[0])) // output will be undefined

so just change your code like this:

 onclick={this.submitchoice}

and find another way to pass data, since you are just passing static dammy data it should not be much issue anyway.

score:1

i went for a different test method in the end. this passes:

  it('should call the submitchoice method on click', () => {

    //arrange
    const spy = jest.spyon(app.prototype, 'submitchoice'); 
    const app = shallow(<app />);

    //act
    const button = app.find('#buttonoption1')
    button.simulate('click');

    //assert
    expect(spy).tobecalled();

 })

Related Query

More Query from same tag