I'm currently facing an issue in one of my unit tests where I am testing the removal of ng-dirty when using setPristine on an input element. Even after calling setPristine, the ng-dirty is not being removed.
My suspicion is that I may be incorrectly implementing the setPristine method.
The specific logic I am attempting to test includes:
- Adding text to the input
- Testing for ng-dirty and then setting it pristine
- Checking for ng-dirty status again
n
/**
Add text to your input,
then test for ng-dirty set the setPristine,
then check for ng-dirty again.
*/
it('should set pristine', function() {
element = angular.element('<input ng-model="temp"></input>');
element = compile(element)(scope);
scope.$digest();
element.val("Some Input");
element.triggerHandler("change");
expect(element.hasClass('ng-dirty')).toBe(true);
element.triggerHandler('setPristine');
console.log(element);
expect(element.hasClass('ng-dirty')).toBe(false);
});
This code snippet logs:
<input ng-model="temp" class="ng-scope ng-valid ng-dirty">
If anyone can provide guidance on how to resolve this, I would greatly appreciate it.
Thank you in advance