Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit ed78f0d

Browse files
committed
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
1 parent dbffbef commit ed78f0d

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

test/matchers.js

+9
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@ beforeEach(function() {
3636
toBeDirty: cssMatcher('ng-dirty', 'ng-pristine'),
3737
toBePristine: cssMatcher('ng-pristine', 'ng-dirty'),
3838

39+
toEqual: function(expected) {
40+
if (this.actual && this.actual.$$log) {
41+
this.actual = (typeof expected === 'string')
42+
? this.actual.toString()
43+
: this.actual.toArray();
44+
}
45+
return jasmine.Matchers.prototype.toEqual.call(this, expected);
46+
},
47+
3948
toEqualData: function(expected) {
4049
return angular.equals(this.actual, expected);
4150
},

test/testabilityPatch.js

+32
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,35 @@ function assertVisible(node) {
185185
}
186186
}
187187

188+
function provideLog($provide) {
189+
$provide.factory('log', function() {
190+
var messages = [];
191+
192+
function log(msg) {
193+
messages.push(msg);
194+
return msg;
195+
}
196+
197+
log.toString = function() {
198+
return messages.join('; ');
199+
}
200+
201+
log.toArray = function() {
202+
return messages;
203+
}
204+
205+
log.reset = function() {
206+
messages = [];
207+
}
208+
209+
log.fn = function(msg) {
210+
return function() {
211+
log(msg);
212+
}
213+
}
214+
215+
log.$$log = true;
216+
217+
return log;
218+
});
219+
}

0 commit comments

Comments
 (0)