From 0fbaa2f12ab96328fe2e7b4b9f3ec0c8d7f30e37 Mon Sep 17 00:00:00 2001 From: Di Peng Date: Mon, 18 Jul 2011 15:31:14 -0700 Subject: feat(TzDate): add mock "toString" method to TzDate. - If the third param of TzDate constructor is defined, toStirng will just return this third parameter. Otherwise, toString will still be treated as unimplemented method --- src/angular-mocks.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/angular-mocks.js b/src/angular-mocks.js index 20423f05..b105e22b 100644 --- a/src/angular-mocks.js +++ b/src/angular-mocks.js @@ -457,7 +457,7 @@ function MockLogFactory() { * * */ -function TzDate(offset, timestamp) { +function TzDate(offset, timestamp, toStringVal) { if (angular.isString(timestamp)) { var tsStr = timestamp; @@ -481,6 +481,10 @@ function TzDate(offset, timestamp) { return this.date.getTime() - this.offsetDiff; }; + this.toString = function() { + return toStringVal; + } + this.toLocaleDateString = function() { return this.date.toLocaleDateString(); }; @@ -551,6 +555,8 @@ function TzDate(offset, timestamp) { 'toLocaleTimeString', 'toSource', 'toString', 'toTimeString', 'toUTCString', 'valueOf']; angular.forEach(unimplementedMethods, function(methodName) { + if (methodName == 'toString' && toStringVal) return; + self[methodName] = function() { throw { name: "MethodNotImplemented", -- cgit v1.2.3