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

Commit 3f0bc0e

Browse files
committed
[WIP] Drop @this in tests & src/ngScenario/dsl.js
1 parent be98953 commit 3f0bc0e

14 files changed

+63
-63
lines changed

src/ngScenario/dsl.js

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
/* eslint-disable no-invalid-this */
4+
35
/**
46
* Shared DSL statements that are useful to all scenarios.
57
*/
@@ -9,8 +11,8 @@
911
* pause() pauses until you call resume() in the console
1012
*/
1113
angular.scenario.dsl('pause', function() {
12-
return /* @this */ function() {
13-
return this.addFuture('pausing for you to resume', /* @this */ function(done) {
14+
return function() {
15+
return this.addFuture('pausing for you to resume', function(done) {
1416
this.emit('InteractivePause', this.spec, this.step);
1517
this.$window.resume = function() { done(); };
1618
});
@@ -22,8 +24,8 @@ angular.scenario.dsl('pause', function() {
2224
* sleep(seconds) pauses the test for specified number of seconds
2325
*/
2426
angular.scenario.dsl('sleep', function() {
25-
return /* @this */ function(time) {
26-
return this.addFuture('sleep for ' + time + ' seconds', /* @this */ function(done) {
27+
return function(time) {
28+
return this.addFuture('sleep for ' + time + ' seconds', function(done) {
2729
this.$window.setTimeout(function() { done(null, time * 1000); }, time * 1000);
2830
});
2931
};
@@ -48,7 +50,7 @@ angular.scenario.dsl('browser', function() {
4850

4951
chain.navigateTo = function(url, delegate) {
5052
var application = this.application;
51-
return this.addFuture("browser navigate to '" + url + "'", /* @this */ function(done) {
53+
return this.addFuture("browser navigate to '" + url + "'", function(done) {
5254
if (delegate) {
5355
url = delegate.call(this, url);
5456
}
@@ -148,7 +150,7 @@ angular.scenario.dsl('expect', function() {
148150
return chain;
149151
};
150152

151-
return /* @this */ function(future) {
153+
return function(future) {
152154
this.future = future;
153155
return chain;
154156
};
@@ -162,7 +164,7 @@ angular.scenario.dsl('expect', function() {
162164
* using('#foo', "'Foo' text field").input('bar')
163165
*/
164166
angular.scenario.dsl('using', function() {
165-
return /* @this */ function(selector, label) {
167+
return function(selector, label) {
166168
this.selector = _jQuery.trim((this.selector || '') + ' ' + selector);
167169
if (angular.isString(label) && label.length) {
168170
this.label = label + ' ( ' + this.selector + ' )';
@@ -178,7 +180,7 @@ angular.scenario.dsl('using', function() {
178180
* binding(name) returns the value of the first matching binding
179181
*/
180182
angular.scenario.dsl('binding', function() {
181-
return /* @this */ function(name) {
183+
return function(name) {
182184
return this.addFutureAction("select binding '" + name + "'",
183185
function($window, $document, done) {
184186
var values = $document.elements().bindings($window.angular.element, name);
@@ -203,7 +205,7 @@ angular.scenario.dsl('input', function() {
203205

204206
chain.enter = function(value, event) {
205207
return this.addFutureAction("input '" + this.name + "' enter '" + value + "'",
206-
/* @this */ function($window, $document, done) {
208+
function($window, $document, done) {
207209
var input = $document.elements('[ng\\:model="$1"]', this.name).filter(':input');
208210
input.val(value);
209211
input.trigger(event || (supportInputEvent ? 'input' : 'change'));
@@ -213,7 +215,7 @@ angular.scenario.dsl('input', function() {
213215

214216
chain.check = function() {
215217
return this.addFutureAction("checkbox '" + this.name + "' toggle",
216-
/* @this */ function($window, $document, done) {
218+
function($window, $document, done) {
217219
var input = $document.elements('[ng\\:model="$1"]', this.name).filter(':checkbox');
218220
input.trigger('click');
219221
done();
@@ -222,7 +224,7 @@ angular.scenario.dsl('input', function() {
222224

223225
chain.select = function(value) {
224226
return this.addFutureAction("radio button '" + this.name + "' toggle '" + value + "'",
225-
/* @this */ function($window, $document, done) {
227+
function($window, $document, done) {
226228
var input = $document.
227229
elements('[ng\\:model="$1"][value="$2"]', this.name, value).filter(':radio');
228230
input.trigger('click');
@@ -231,13 +233,13 @@ angular.scenario.dsl('input', function() {
231233
};
232234

233235
chain.val = function() {
234-
return this.addFutureAction("return input val", /* @this */ function($window, $document, done) {
236+
return this.addFutureAction("return input val", function($window, $document, done) {
235237
var input = $document.elements('[ng\\:model="$1"]', this.name).filter(':input');
236238
done(null,input.val());
237239
});
238240
};
239241

240-
return /* @this */ function(name) {
242+
return function(name) {
241243
this.name = name;
242244
return chain;
243245
};
@@ -283,7 +285,7 @@ angular.scenario.dsl('repeater', function() {
283285
});
284286
};
285287

286-
return /* @this */ function(selector, label) {
288+
return function(selector, label) {
287289
this.dsl.using(selector, label);
288290
return chain;
289291
};
@@ -299,13 +301,13 @@ angular.scenario.dsl('select', function() {
299301

300302
chain.option = function(value) {
301303
return this.addFutureAction("select '" + this.name + "' option '" + value + "'",
302-
/* @this */ function($window, $document, done) {
304+
function($window, $document, done) {
303305
var select = $document.elements('select[ng\\:model="$1"]', this.name);
304306
var option = select.find('option[value="' + value + '"]');
305307
if (option.length) {
306308
select.val(value);
307309
} else {
308-
option = select.find('option').filter(/* @this */ function() {
310+
option = select.find('option').filter(function() {
309311
return _jQuery(this).text() === value;
310312
});
311313
if (!option.length) {
@@ -325,15 +327,15 @@ angular.scenario.dsl('select', function() {
325327
chain.options = function() {
326328
var values = arguments;
327329
return this.addFutureAction("select '" + this.name + "' options '" + values + "'",
328-
/* @this */ function($window, $document, done) {
330+
function($window, $document, done) {
329331
var select = $document.elements('select[multiple][ng\\:model="$1"]', this.name);
330332
select.val(values);
331333
select.trigger('change');
332334
done();
333335
});
334336
};
335337

336-
return /* @this */ function(name) {
338+
return function(name) {
337339
this.name = name;
338340
return chain;
339341
};
@@ -373,7 +375,7 @@ angular.scenario.dsl('element', function() {
373375

374376
chain.click = function() {
375377
return this.addFutureAction("element '" + this.label + "' click",
376-
/* @this */ function($window, $document, done) {
378+
function($window, $document, done) {
377379
var elements = $document.elements();
378380
var href = elements.attr('href');
379381
var eventProcessDefault = elements.trigger('click')[0];
@@ -390,7 +392,7 @@ angular.scenario.dsl('element', function() {
390392

391393
chain.dblclick = function() {
392394
return this.addFutureAction("element '" + this.label + "' dblclick",
393-
/* @this */ function($window, $document, done) {
395+
function($window, $document, done) {
394396
var elements = $document.elements();
395397
var href = elements.attr('href');
396398
var eventProcessDefault = elements.trigger('dblclick')[0];
@@ -434,7 +436,7 @@ angular.scenario.dsl('element', function() {
434436

435437
chain.query = function(fn) {
436438
return this.addFutureAction('element ' + this.label + ' custom query',
437-
/* @this */ function($window, $document, done) {
439+
function($window, $document, done) {
438440
fn.call(this, $document.elements(), done);
439441
});
440442
};
@@ -468,7 +470,7 @@ angular.scenario.dsl('element', function() {
468470
};
469471
});
470472

471-
return /* @this */ function(selector, label) {
473+
return function(selector, label) {
472474
this.dsl.using(selector, label);
473475
return chain;
474476
};

test/AngularSpec.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1418,7 +1418,7 @@ describe('angular', function() {
14181418
});
14191419
var log = [];
14201420
var self = {};
1421-
forEach(obj, /* @this */ function(val, key, collection) {
1421+
forEach(obj, function(val, key, collection) {
14221422
expect(this).toBe(self);
14231423
expect(collection).toBe(obj);
14241424
log.push(key + '=' + val);
@@ -1437,7 +1437,7 @@ describe('angular', function() {
14371437
};
14381438
var log = [];
14391439
var self = {};
1440-
forEach(obj, /* @this */ function(val, key, collection) {
1440+
forEach(obj, function(val, key, collection) {
14411441
expect(this).toBe(self);
14421442
expect(collection).toBe(obj);
14431443
log.push(key + '=' + val);
@@ -1452,7 +1452,7 @@ describe('angular', function() {
14521452
function testForEachSpec(expectedSize, collection) {
14531453
var that = {};
14541454

1455-
forEach(collection, /* @this */ function(value, key, collectionArg) {
1455+
forEach(collection, function(value, key, collectionArg) {
14561456
expect(collectionArg).toBe(collection);
14571457
expect(collectionArg[key]).toBe(value);
14581458

test/auto/injectorSpec.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,7 @@ describe('injector', function() {
903903
expect($injector.invoke(function(book, author) {
904904
return author + ':' + book;
905905
})).toEqual('melville:moby');
906-
expect($injector.invoke(/* @this */ function(book, author) {
906+
expect($injector.invoke(function(book, author) {
907907
expect(this).toEqual($injector);
908908
return author + ':' + book;
909909
}, $injector)).toEqual('melville:moby');
@@ -915,7 +915,7 @@ describe('injector', function() {
915915
return author + ':' + book;
916916
})).toEqual('melville:moby');
917917
expect($injector.invoke(
918-
/* @this */ function(book, author, chapter) {
918+
function(book, author, chapter) {
919919
expect(this).toEqual($injector);
920920
return author + ':' + book + '-' + chapter;
921921
}, $injector, {author:'m', chapter:'ch1'})).toEqual('m:moby-ch1');
@@ -926,7 +926,7 @@ describe('injector', function() {
926926
expect($injector.invoke(extend(function(b, a) {
927927
return a + ':' + b;
928928
}, {$inject:['book', 'author']}))).toEqual('melville:moby');
929-
expect($injector.invoke(extend(/* @this */ function(b, a) {
929+
expect($injector.invoke(extend(function(b, a) {
930930
expect(this).toEqual($injector);
931931
return a + ':' + b;
932932
}, {$inject:['book', 'author']}), $injector)).toEqual('melville:moby');
@@ -937,7 +937,7 @@ describe('injector', function() {
937937
expect($injector.invoke(function(book, author) {
938938
return author + ':' + book;
939939
})).toEqual('melville:moby');
940-
expect($injector.invoke(/* @this */ function(book, author) {
940+
expect($injector.invoke(function(book, author) {
941941
expect(this).toEqual($injector);
942942
return author + ':' + book;
943943
}, $injector)).toEqual('melville:moby');
@@ -1146,7 +1146,6 @@ describe('strict-di injector', function() {
11461146
it('should always use provider as `this` when invoking a factory', function() {
11471147
var called = false;
11481148

1149-
/* @this */
11501149
function factoryFn() {
11511150
called = true;
11521151
expect(typeof this.$get).toBe('function');

test/helpers/privateMocks.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function baseThey(msg, vals, spec, itFn) {
1212

1313
angular.forEach(vals, function(val, key) {
1414
var m = msg.split('$prop').join(angular.toJson(valsIsArray ? val : key));
15-
itFn(m, /* @this */ function() {
15+
itFn(m, function() {
1616
spec.call(this, val);
1717
});
1818
});

test/helpers/testabilityPatch.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ beforeEach(function() {
5151
angular.element(window.document.body).empty().removeData();
5252
});
5353

54-
afterEach(/* @this */ function() {
54+
afterEach(function() {
5555
var count, cache;
5656

5757
// both of these nodes are persisted across tests

test/jqLiteSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ describe('jqLite', function() {
10991099
it('should bind to all elements and return functions', function() {
11001100
var selected = jqLite([a, b]);
11011101
var log = '';
1102-
expect(selected.on('click', /* @this */ function() {
1102+
expect(selected.on('click', function() {
11031103
log += 'click on: ' + jqLite(this).text() + ';';
11041104
})).toEqual(selected);
11051105
browserTrigger(a, 'click');

test/ng/compileSpec.js

-1
Original file line numberDiff line numberDiff line change
@@ -3664,7 +3664,6 @@ describe('$compile', function() {
36643664

36653665
it('should call `$onInit`, if provided, after all the controllers on the element have been initialized', function() {
36663666

3667-
/* @this */
36683667
function check() {
36693668
expect(this.element.controller('d1').id).toEqual(1);
36703669
expect(this.element.controller('d2').id).toEqual(2);

test/ng/parseSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2169,7 +2169,7 @@ describe('parser', function() {
21692169
// There is no "strict mode" in IE9
21702170
if (!msie || msie > 9) {
21712171
it('should set no context to functions returned by other functions', function() {
2172-
scope.getter = function() { return /* @this */ function() { expect(this).toBeUndefined(); }; };
2172+
scope.getter = function() { return function() { expect(this).toBeUndefined(); }; };
21732173
scope.$eval("getter()()");
21742174
});
21752175
}

test/ngMock/angular-mocksSpec.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -1743,23 +1743,23 @@ describe('ngMock', function() {
17431743
angular.forEach(['expectRoute', 'whenRoute'], function(routeShortcut) {
17441744
var methods = ['GET', 'POST', 'PUT', 'PATCH', 'DELETE', 'JSONP'];
17451745
they('should provide ' + routeShortcut + ' shortcut with $prop method', methods,
1746-
/* @this */ function() {
1746+
function() {
17471747
hb[routeShortcut](this, '/route').respond('path');
17481748
hb(this, '/route', undefined, callback);
17491749
hb.flush();
17501750
expect(callback).toHaveBeenCalledOnceWith(200, 'path', '', '');
17511751
}
17521752
);
17531753
they('should match colon deliminated parameters in ' + routeShortcut + ' $prop method', methods,
1754-
/* @this */ function() {
1754+
function() {
17551755
hb[routeShortcut](this, '/route/:id/path/:s_id').respond('path');
17561756
hb(this, '/route/123/path/456', undefined, callback);
17571757
hb.flush();
17581758
expect(callback).toHaveBeenCalledOnceWith(200, 'path', '', '');
17591759
}
17601760
);
17611761
they('should ignore query param when matching in ' + routeShortcut + ' $prop method', methods,
1762-
/* @this */ function() {
1762+
function() {
17631763
hb[routeShortcut](this, '/route/:id').respond('path');
17641764
hb(this, '/route/123?q=str&foo=bar', undefined, callback);
17651765
hb.flush();
@@ -2032,7 +2032,7 @@ describe('ngMock', function() {
20322032
{ name: 'flurp', id: 2 }
20332033
];
20342034
module(function($controllerProvider) {
2035-
$controllerProvider.register('testCtrl', /* @this */ function() {
2035+
$controllerProvider.register('testCtrl', function() {
20362036
called = true;
20372037
expect(this.data).toBe(data);
20382038
});
@@ -2052,7 +2052,7 @@ describe('ngMock', function() {
20522052
{ name: 'flurp', id: 2 }
20532053
];
20542054
module(function($controllerProvider) {
2055-
$controllerProvider.register('testCtrl', /* @this */ function() {
2055+
$controllerProvider.register('testCtrl', function() {
20562056
called = true;
20572057
expect(this.data).toBe(data);
20582058

@@ -2921,7 +2921,7 @@ describe('sharedInjector', function() {
29212921
}));
29222922

29232923
it("prevents nested use of sharedInjector()", function() {
2924-
var test = ngMockTest(/* @this */ function() {
2924+
var test = ngMockTest(function() {
29252925
sdescribe("outer", function() {
29262926

29272927
module.sharedInjector();
@@ -2962,7 +2962,7 @@ describe('sharedInjector', function() {
29622962

29632963
// run a set of test cases in the sdescribe stub test framework
29642964
function ngMockTest(define) {
2965-
return /* @this */ function() {
2965+
return function() {
29662966
var spec = this;
29672967
module.$$currentSpec(null);
29682968

test/ngScenario/ApplicationSpec.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('angular.scenario.Application', function() {
4848
app.getWindow_ = function() {
4949
return testWindow;
5050
};
51-
app.executeAction(/* @this */ function($window, $document) {
51+
app.executeAction(function($window, $document) {
5252
expect(this).toEqual(app);
5353
expect($document).toEqual(_jQuery($window.document));
5454
expect($window).toEqual(testWindow);

0 commit comments

Comments
 (0)