1

Unable to simulate click action on radio button in unit test.

This is the 'it' block :

var element = '<div> <my-directive></my-directive></div>';
element = $compile(element)($rootScope);
$rootScope.$digest();

var radio1Button  = element.find('input')[1];
var radio2Button  = element.find('input')[2];

angular.element(radio2Button).trigger('click');
expect(radioModel).toBe('radio2Button');         

This test is failing , expected is radio2button should get clicked and the ng-model value will change from radio1Button to radio2Button.

1 Answer 1

1

Use triggerHandler instead

angular.element(radio2Button).triggerHandler('click');

Consider the similar answer here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.