Skip to content
This repository was archived by the owner on Feb 22, 2018. It is now read-only.

Commit b09f378

Browse files
vsavkinchirayuk
authored andcommitted
refactor(tests): remove unnecessary inject calls
Some tests rely on the fact that dependencies can be injected into `it`s, but some call `inject` explicitly. This PR makes tests more consistent by removing unnecessary inject calls. Closes #1218
1 parent 42ca817 commit b09f378

16 files changed

+121
-130
lines changed

test/animate/animation_loop_spec.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ main() {
88
TestBed _;
99
AnimationLoop runner;
1010
MockAnimationFrame frame;
11-
beforeEach(async(inject((TestBed tb, VmTurnZone zone) {
11+
beforeEach(async((TestBed tb, VmTurnZone zone) {
1212
_ = tb;
1313
frame = new MockAnimationFrame();
1414
runner = new AnimationLoop(frame, new Profiler(), zone);
15-
})));
15+
}));
1616

1717
it('should play animations with window animation frames', async(() {
1818
var animation = new MockAnimation();

test/animate/animation_optimizer_spec.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ _run({bool animationsAllowed}) {
77
describe('animationsAllowed=$animationsAllowed', () {
88
TestBed _;
99
AnimationOptimizer optimizer;
10-
beforeEach(inject((TestBed tb, Expando expand) {
10+
beforeEach((TestBed tb, Expando expand) {
1111
_ = tb;
1212
optimizer = new AnimationOptimizer(expand)..animationsAllowed = animationsAllowed;
13-
}));
13+
});
1414

1515
it('should prevent animations on child elements', () {
1616
var animation = new NoOpAnimation();

test/animate/css_animate_spec.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ _run({bool animationsAllowed}) {
1111
Animate animate;
1212
MockAnimationLoop runner;
1313

14-
beforeEach(inject((TestBed tb, Expando expand) {
14+
beforeEach((TestBed tb, Expando expand) {
1515
_ = tb;
1616
runner = new MockAnimationLoop(animationsAllowed);
1717
animate = new CssAnimate(runner,
1818
new CssAnimationMap(), new AnimationOptimizer(expand));
1919
animate.animationsAllowed = animationsAllowed;
20-
}));
20+
});
2121

2222
it('should add a css class to an element node', async(() {
2323
_.compile('<div></div>');

test/animate/css_animation_spec.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ main() {
66
describe('CssAnimation', () {
77
TestBed _;
88

9-
beforeEach(inject((TestBed tb) => _ = tb));
9+
beforeEach((TestBed tb) => _ = tb);
1010
afterEach(() => _.rootElements.forEach((e) => e.remove()));
1111

1212
it('should correctly respond to an animation lifecycle', async(() {

test/cache/cache_spec.dart

+12-12
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ void main() {
6767

6868
describe('put, get & remove', () {
6969

70-
it('should add cache entries via add and retrieve them via get', inject(() {
70+
it('should add cache entries via add and retrieve them via get', () {
7171
var obj = {'bar':'baz'};
7272
cache.put('key1', 'bar');
7373
cache.put('key2', obj);
7474

7575
expect(cache.get('key2')).toBe(obj);
7676
expect(cache.get('key1')).toBe('bar');
77-
}));
77+
});
7878

7979

80-
it('should remove entries via remove', inject(() {
80+
it('should remove entries via remove', () {
8181
cache.put('k1', 'foo');
8282
cache.put('k2', 'bar');
8383

@@ -90,22 +90,22 @@ void main() {
9090

9191
expect(cache.get('k1')).toBeNull();
9292
expect(cache.get('k2')).toBeNull();
93-
}));
93+
});
9494

9595

96-
it('should return null when entry does not exist', inject(() {
96+
it('should return null when entry does not exist', () {
9797
expect(cache.remove('non-existent')).toBeNull();
98-
}));
98+
});
9999

100-
it("should return value from put", inject(() {
100+
it("should return value from put", () {
101101
var obj = {};
102102
expect(cache.put('k1', obj)).toBe(obj);
103-
}));
103+
});
104104
});
105105

106106

107107
describe('removeAll', () {
108-
it('should blow away all data', inject(() {
108+
it('should blow away all data', () {
109109
cache.put('id1', 1);
110110
cache.put('id2', 2);
111111
cache.put('id3', 3);
@@ -115,13 +115,13 @@ void main() {
115115
expect(cache.get('id1')).toBeNull();
116116
expect(cache.get('id2')).toBeNull();
117117
expect(cache.get('id3')).toBeNull();
118-
}));
118+
});
119119
});
120120
});
121121

122122
// TODO(chirayu): Add a lot more tests and tests and don't rely on toString()
123123
describe('LRU cache', () {
124-
it('should have LRU behavior with ordering keys and eviction', inject(() {
124+
it('should have LRU behavior with ordering keys and eviction', () {
125125
var cache = new LruCache<int, int>(capacity: 4);
126126
cache.put(1, 10);
127127
cache.put(2, 20);
@@ -146,7 +146,7 @@ void main() {
146146
expect(stats.size).toEqual(0);
147147
expect(stats.hits).toEqual(2);
148148
expect(stats.misses).toEqual(1);
149-
}));
149+
});
150150

151151
it('should hold nothing if capacity is zero', () {
152152
var cache = new LruCache<int, int>(capacity: 0);

test/change_detection/watch_group_spec.dart

+4-4
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@ void main() {
2323
Parser parser;
2424
ASTParser astParser;
2525

26-
beforeEach(inject((Logger _logger, Parser _parser, ASTParser _astParser) {
26+
beforeEach((Logger _logger, Parser _parser, ASTParser _astParser) {
2727
context = {};
2828
var getterFactory = new DynamicFieldGetterFactory();
2929
changeDetector = new DirtyCheckingChangeDetector(getterFactory);
3030
watchGrp = new RootWatchGroup(getterFactory, changeDetector, context);
3131
logger = _logger;
3232
parser = _parser;
3333
astParser = _astParser;
34-
}));
34+
});
3535

3636
AST parse(String expression) => astParser(expression);
3737

@@ -64,13 +64,13 @@ void main() {
6464
expect(logger).toEqual(list);
6565
}
6666

67-
beforeEach(inject((Logger _logger) {
67+
beforeEach((Logger _logger) {
6868
context = {};
6969
var getterFactory = new DynamicFieldGetterFactory();
7070
changeDetector = new DirtyCheckingChangeDetector(getterFactory);
7171
watchGrp = new RootWatchGroup(getterFactory, changeDetector, context);
7272
logger = _logger;
73-
}));
73+
});
7474

7575
it('should have a toString for debugging', () {
7676
watchGrp.watch(parse('a'), (v, p) {});

test/core/scope_spec.dart

+35-36
Original file line numberDiff line numberDiff line change
@@ -654,7 +654,7 @@ void main() {
654654

655655

656656
it('should skip scopes which dont have given event',
657-
inject((RootScope rootScope, Logger log) {
657+
(RootScope rootScope, Logger log) {
658658
var child1 = rootScope.createChild('A');
659659
rootScope.createChild('A1');
660660
rootScope.createChild('A2');
@@ -663,7 +663,7 @@ void main() {
663663
child2.on('event').listen((e) => log(e.data));
664664
rootScope.broadcast('event', 'OK');
665665
expect(log).toEqual(['OK']);
666-
}));
666+
});
667667
});
668668

669669

@@ -847,14 +847,14 @@ void main() {
847847
});
848848

849849

850-
it(r'should execute and return value and update', inject(
851-
(RootScope rootScope, ExceptionHandler e) {
852-
LoggingExceptionHandler exceptionHandler = e;
853-
rootScope.context['name'] = 'abc';
854-
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
855-
expect(log).toEqual('digest;digest;');
856-
exceptionHandler.assertEmpty();
857-
}));
850+
it(r'should execute and return value and update',
851+
(RootScope rootScope, ExceptionHandler e) {
852+
LoggingExceptionHandler exceptionHandler = e;
853+
rootScope.context['name'] = 'abc';
854+
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
855+
expect(log).toEqual('digest;digest;');
856+
exceptionHandler.assertEmpty();
857+
});
858858

859859

860860
it(r'should execute and return value and update', (RootScope rootScope) {
@@ -924,14 +924,14 @@ void main() {
924924
exceptionHandler.assertEmpty();
925925
});
926926

927-
it(r'should execute and return value and update', inject(
928-
(RootScope rootScope, ExceptionHandler e) {
929-
LoggingExceptionHandler exceptionHandler = e;
930-
rootScope.context['name'] = 'abc';
931-
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
932-
expect(log).toEqual('digest;digest;');
933-
exceptionHandler.assertEmpty();
934-
}));
927+
it(r'should execute and return value and update',
928+
(RootScope rootScope, ExceptionHandler e) {
929+
LoggingExceptionHandler exceptionHandler = e;
930+
rootScope.context['name'] = 'abc';
931+
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
932+
expect(log).toEqual('digest;digest;');
933+
exceptionHandler.assertEmpty();
934+
});
935935

936936
it(r'should execute and return value and update', (RootScope rootScope) {
937937
rootScope.context['name'] = 'abc';
@@ -1092,23 +1092,22 @@ void main() {
10921092
});
10931093

10941094

1095-
it(r'should run digest multiple times', inject(
1096-
(RootScope rootScope) {
1097-
// tests a traversal edge case which we originally missed
1098-
var log = [];
1099-
var childA = rootScope.createChild({'log': log});
1100-
var childB = rootScope.createChild({'log': log});
1095+
it(r'should run digest multiple times', (RootScope rootScope) {
1096+
// tests a traversal edge case which we originally missed
1097+
var log = [];
1098+
var childA = rootScope.createChild({'log': log});
1099+
var childB = rootScope.createChild({'log': log});
11011100

1102-
rootScope.context['log'] = log;
1101+
rootScope.context['log'] = log;
11031102

1104-
rootScope.watch("log.add('r')", (_, __) => null);
1105-
childA.watch("log.add('a')", (_, __) => null);
1106-
childB.watch("log.add('b')", (_, __) => null);
1103+
rootScope.watch("log.add('r')", (_, __) => null);
1104+
childA.watch("log.add('a')", (_, __) => null);
1105+
childB.watch("log.add('b')", (_, __) => null);
11071106

1108-
// init
1109-
rootScope.digest();
1110-
expect(log.join('')).toEqual('rabrab');
1111-
}));
1107+
// init
1108+
rootScope.digest();
1109+
expect(log.join('')).toEqual('rabrab');
1110+
});
11121111

11131112

11141113
it(r'should repeat watch cycle while model changes are identified', (RootScope rootScope) {
@@ -1165,7 +1164,7 @@ void main() {
11651164
});
11661165

11671166

1168-
it(r'should return a function that allows listeners to be unregistered', inject(
1167+
it(r'should return a function that allows listeners to be unregistered',
11691168
(RootScope rootScope) {
11701169
var listener = guinness.createSpy('watch listener');
11711170
var watch;
@@ -1185,7 +1184,7 @@ void main() {
11851184
watch.remove();
11861185
rootScope.digest(); //trigger
11871186
expect(listener).not.toHaveBeenCalled();
1188-
}));
1187+
});
11891188

11901189

11911190
it(r'should be possible to remove every watch',
@@ -1228,7 +1227,7 @@ void main() {
12281227

12291228

12301229
it(r'should always call the watchr with newVal and oldVal equal on the first run',
1231-
inject((RootScope rootScope) {
1230+
(RootScope rootScope) {
12321231
var log = [];
12331232
var logger = (newVal, oldVal) {
12341233
var val = (newVal == oldVal || (newVal != oldVal && oldVal != newVal)) ? newVal : 'xxx';
@@ -1253,7 +1252,7 @@ void main() {
12531252
log = [];
12541253
rootScope.digest();
12551254
expect(log).toEqual([]);
1256-
}));
1255+
});
12571256

12581257

12591258
it('should properly watch constants', (RootScope rootScope, Logger log) {

0 commit comments

Comments
 (0)