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

Commit c2173c1

Browse files
committed
test(privateMocks): allow replacing $prop with strings with special RegExp semantics
`baseThey` used to construct the testcase description by replacing `$prop` using a RegExp. If the replacement string contained `$&` (which has a special meaning with RegExps), the resulting string was not as expected.x
1 parent 0b94e8a commit c2173c1

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

test/helpers/privateMocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function baseThey(msg, vals, spec, itFn) {
1111
var valsIsArray = angular.isArray(vals);
1212

1313
angular.forEach(vals, function(val, key) {
14-
var m = msg.replace(/\$prop/g, angular.toJson(valsIsArray ? val : key));
14+
var m = msg.split('$prop').join(angular.toJson(valsIsArray ? val : key));
1515
itFn(m, function() {
1616
/* jshint -W040 : ignore possible strict violation due to use of this */
1717
spec.call(this, val);

test/helpers/privateMocksSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ describe('private mocks', function() {
2222
expect(window.it).toHaveBeenCalledWith('should fight "fire" with "fire"', jasmine.any(Function));
2323
});
2424

25+
it('should handle replacement strings containing `$&` correctly', function() {
26+
spyOn(window, 'it');
27+
28+
they('should replace dollar-prop with $prop', ['$&']);
29+
expect(window.it).toHaveBeenCalledWith('should replace dollar-prop with "$&"', jasmine.any(Function));
30+
});
31+
2532
it('should pass each item in an array to the handler', function() {
2633
var handlerSpy = jasmine.createSpy('handler');
2734
spyOn(window, 'it').andCallFake(function(msg, handler) {

0 commit comments

Comments
 (0)