Skip to content

Instantly share code, notes, and snippets.

@hawx
Created April 24, 2017 10:42
Show Gist options
  • Save hawx/fca41eb23e573f4ff2252e9c9b5aca89 to your computer and use it in GitHub Desktop.
Save hawx/fca41eb23e573f4ff2252e9c9b5aca89 to your computer and use it in GitHub Desktop.
Testing radio buttons in Angular...
it('test', () => {
const element = `
<section>
<label>
<input type="radio"
ng-value="true"
name="test"
ng-model="$ctrl.value"
hidden
required />
Yes
</label>
<label>
<input type="radio"
ng-value="false"
name="test"
ng-model="$ctrl.value"
hidden
required />
No
</label>
<div ng-if="$ctrl.value">what</div>
</section>
`;
let compiled = $compile(element)($scope);
$scope.$digest();
compiled.find('label:first-child input').click().trigger('click');
$scope.$digest();
assert.equal(compiled.find('div').text(), 'what');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment