diff options
| author | Vojta Jina | 2011-06-23 16:52:47 +0200 | 
|---|---|---|
| committer | Igor Minar | 2011-08-19 01:17:09 -0700 | 
| commit | f6bcbb53f056372d6778fedfc793435fc2e88e11 (patch) | |
| tree | 3d122d20b30f8b882873f70f6b86207a6dc056db | |
| parent | 53a4580d956248cfef84c4d11350a54d27211cf7 (diff) | |
| download | angular.js-f6bcbb53f056372d6778fedfc793435fc2e88e11.tar.bz2 | |
feat(test): toHaveBeenCalledOnce jasmine matcher
| -rw-r--r-- | test/testabilityPatch.js | 22 | 
1 files changed, 22 insertions, 0 deletions
| diff --git a/test/testabilityPatch.js b/test/testabilityPatch.js index bb553d68..744aa4cc 100644 --- a/test/testabilityPatch.js +++ b/test/testabilityPatch.js @@ -90,6 +90,28 @@ beforeEach(function(){          return "Expected " + expected + " to match an Error with message " + toJson(messageRegexp);        };        return this.actual.name == 'Error' && messageRegexp.test(this.actual.message); +    }, + +    toHaveBeenCalledOnce: function() { +      if (arguments.length > 0) { +        throw new Error('toHaveBeenCalledOnce does not take arguments, use toHaveBeenCalledWith'); +      } + +      if (!jasmine.isSpy(this.actual)) { +        throw new Error('Expected a spy, but got ' + jasmine.pp(this.actual) + '.'); +      } + +      this.message = function() { +        var msg = 'Expected spy ' + this.actual.identity + ' to have been called once, but was ', +            count = this.actual.callCount; +        return [ +          count == 0 ? msg + 'never called.' +                     : msg + 'called ' + count + ' times.', +          msg.replace('to have', 'not to have') + 'called once.' +        ]; +      }; + +      return this.actual.callCount == 1;      }    }); | 
