mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-05-21 21:01:51 +00:00
chore(log): generic test log service with custom toEquals matcher
- any test that needs a logger can just inject provideLog - logger has susict api that makes tests more readable - custom toEquals matcher allows for pretty expectations
This commit is contained in:
parent
dbffbefb7c
commit
ed78f0d830
2 changed files with 41 additions and 0 deletions
|
|
@ -36,6 +36,15 @@ beforeEach(function() {
|
||||||
toBeDirty: cssMatcher('ng-dirty', 'ng-pristine'),
|
toBeDirty: cssMatcher('ng-dirty', 'ng-pristine'),
|
||||||
toBePristine: cssMatcher('ng-pristine', 'ng-dirty'),
|
toBePristine: cssMatcher('ng-pristine', 'ng-dirty'),
|
||||||
|
|
||||||
|
toEqual: function(expected) {
|
||||||
|
if (this.actual && this.actual.$$log) {
|
||||||
|
this.actual = (typeof expected === 'string')
|
||||||
|
? this.actual.toString()
|
||||||
|
: this.actual.toArray();
|
||||||
|
}
|
||||||
|
return jasmine.Matchers.prototype.toEqual.call(this, expected);
|
||||||
|
},
|
||||||
|
|
||||||
toEqualData: function(expected) {
|
toEqualData: function(expected) {
|
||||||
return angular.equals(this.actual, expected);
|
return angular.equals(this.actual, expected);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -185,3 +185,35 @@ function assertVisible(node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function provideLog($provide) {
|
||||||
|
$provide.factory('log', function() {
|
||||||
|
var messages = [];
|
||||||
|
|
||||||
|
function log(msg) {
|
||||||
|
messages.push(msg);
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.toString = function() {
|
||||||
|
return messages.join('; ');
|
||||||
|
}
|
||||||
|
|
||||||
|
log.toArray = function() {
|
||||||
|
return messages;
|
||||||
|
}
|
||||||
|
|
||||||
|
log.reset = function() {
|
||||||
|
messages = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
log.fn = function(msg) {
|
||||||
|
return function() {
|
||||||
|
log(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.$$log = true;
|
||||||
|
|
||||||
|
return log;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue