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

Commit

Permalink
test(privateMocks): allow replacing $prop with strings with special…
Browse files Browse the repository at this point in the history
… 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
  • Loading branch information
gkalpak committed Dec 15, 2015
1 parent 1b25f80 commit 77435fd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion test/helpers/privateMocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function baseThey(msg, vals, spec, itFn) {
var valsIsArray = angular.isArray(vals);

angular.forEach(vals, function(val, key) {
var m = msg.replace(/\$prop/g, angular.toJson(valsIsArray ? val : key));
var m = msg.split('$prop').join(angular.toJson(valsIsArray ? val : key));
itFn(m, function() {
/* jshint -W040 : ignore possible strict violation due to use of this */
spec.call(this, val);
Expand Down
7 changes: 7 additions & 0 deletions test/helpers/privateMocksSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@ describe('private mocks', function() {
expect(window.it).toHaveBeenCalledWith('should fight "fire" with "fire"', jasmine.any(Function));
});

it('should handle replacement strings containing `$&` correctly', function() {
spyOn(window, 'it');

they('should replace dollar-prop with $prop', ['$&']);
expect(window.it).toHaveBeenCalledWith('should replace dollar-prop with "$&"', jasmine.any(Function));
});

it('should pass each item in an array to the handler', function() {
var handlerSpy = jasmine.createSpy('handler');
spyOn(window, 'it').andCallFake(function(msg, handler) {
Expand Down

0 comments on commit 77435fd

Please sign in to comment.