I just had this same issue. What I ended up doing was using sinon.stub to make a fake form object. This object had these properties:
form = {$valid: true, $pristine: false, $dirty: true, $setPristine: function () {scope.newItemForm.$dirty = false, scope.newItemForm.$pristine = true;}};
I then set that fake to equal my scope's newItemForm.
scope.newItemForm = form;
I then tested to see if the behavior was correct, whether scope.newItemForm.$dirty = false and scope.newItemForm.$pristine = true
when $setPristine
was triggered and the opposite when it wasn't supposed to be triggered.
This doesn't mock all the behaviors of $setPristine
, but I figure I just need to know if the method is triggered since I shouldn't be concerned about testing angular's functionality.