I have an angular page with some radio options, that section looks like this (abridged):
div.row-fluid(ng-controller="SearchCtrl")
...
form(name="pForm")
...
div.span4
input(ng-model='form.worktype', type='radio', value='fulltime', name='worktype')
| Full Time
input(ng-model='form.worktype', type='radio', value='parttime', name='worktype')
| Part Time
p hello {{form.worktype}}
The form works, the "p hello {{form.worktype}}" works but I can't seem to find the selection within my e2e test:
it('should select the ', function() {
element('a[href$="addWork"]').click();
input('form.worktype').select('parttime');
expect(binding('form.worktype')).toBe('parttime');
});
returns:
Binding selector 'form.worktype' did not match
and a different approach also fails:
it('should select the ', function() {
element('a[href$="addWork"]').click();
input('form.worktype').select('parttime');
expect(input('form.worktype').val()).toBe('parttime');
});
gives me "fulltime" even though a pause() in the test clearly shows Part time selected.
Any ideas as to how to make this seemingly simple thing pass?
I've encountered the same problem with e2e testing in Angular. Some of the pieces are a little finicky. I could not get binding() to work with my form element binding. I first tried the same thing you did, but the input select for val on radio buttons gets the value assigned to the first radio button it finds, not the one actually selected.
My eventual work around came down to getting the input element with that name that was also checked, and then looking at it's value. This should work for you.
expect(element('input[name="worktype"]:checked').val()).toBe('parttime');
With all the power of bindings and the use of the model, you would think there would be a better solution, but I've found none. Instead, I find myself have to do very specific selectors to get an individual element, and work from there. Less then ideal, but funcitonal.
With that being said, the Angular page on e2e testing suggests reading up on Protractor, because they will be using that in the future, so hopefully when that's ready, we'll be able to have better e2e testing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With