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

refactor(tests): remove unnecessary inject calls #1218

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions test/animate/animation_loop_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ main() {
TestBed _;
AnimationLoop runner;
MockAnimationFrame frame;
beforeEach(async(inject((TestBed tb, VmTurnZone zone) {
beforeEach(async((TestBed tb, VmTurnZone zone) {
_ = tb;
frame = new MockAnimationFrame();
runner = new AnimationLoop(frame, new Profiler(), zone);
})));
}));

it('should play animations with window animation frames', async(() {
var animation = new MockAnimation();
Expand Down
4 changes: 2 additions & 2 deletions test/animate/animation_optimizer_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ main() {
describe('AnimationLoop', () {
TestBed _;
AnimationOptimizer optimizer;
beforeEach(inject((TestBed tb, Expando expand) {
beforeEach((TestBed tb, Expando expand) {
_ = tb;
optimizer = new AnimationOptimizer(expand);
}));
});

it('should prevent animations on child elements', () {
var animation = new NoOpAnimation();
Expand Down
4 changes: 2 additions & 2 deletions test/animate/css_animate_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ main() {
Animate animate;
MockAnimationLoop runner;

beforeEach(inject((TestBed tb, Expando expand) {
beforeEach((TestBed tb, Expando expand) {
_ = tb;
runner = new MockAnimationLoop();
animate = new CssAnimate(runner,
new CssAnimationMap(), new AnimationOptimizer(expand));
}));
});

it('should add a css class to an element node', async(() {
_.compile('<div></div>');
Expand Down
2 changes: 1 addition & 1 deletion test/animate/css_animation_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ main() {
describe('CssAnimation', () {
TestBed _;

beforeEach(inject((TestBed tb) => _ = tb));
beforeEach((TestBed tb) => _ = tb);
afterEach(() => _.rootElements.forEach((e) => e.remove()));

it('should correctly respond to an animation lifecycle', async(() {
Expand Down
24 changes: 12 additions & 12 deletions test/cache/cache_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,17 @@ void main() {

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

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

expect(cache.get('key2')).toBe(obj);
expect(cache.get('key1')).toBe('bar');
}));
});


it('should remove entries via remove', inject(() {
it('should remove entries via remove', () {
cache.put('k1', 'foo');
cache.put('k2', 'bar');

Expand All @@ -90,22 +90,22 @@ void main() {

expect(cache.get('k1')).toBeNull();
expect(cache.get('k2')).toBeNull();
}));
});


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

it("should return value from put", inject(() {
it("should return value from put", () {
var obj = {};
expect(cache.put('k1', obj)).toBe(obj);
}));
});
});


describe('removeAll', () {
it('should blow away all data', inject(() {
it('should blow away all data', () {
cache.put('id1', 1);
cache.put('id2', 2);
cache.put('id3', 3);
Expand All @@ -115,13 +115,13 @@ void main() {
expect(cache.get('id1')).toBeNull();
expect(cache.get('id2')).toBeNull();
expect(cache.get('id3')).toBeNull();
}));
});
});
});

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

it('should hold nothing if capacity is zero', () {
var cache = new LruCache<int, int>(capacity: 0);
Expand Down
8 changes: 4 additions & 4 deletions test/change_detection/watch_group_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ void main() {
Parser parser;
ASTParser astParser;

beforeEach(inject((Logger _logger, Parser _parser, ASTParser _astParser) {
beforeEach((Logger _logger, Parser _parser, ASTParser _astParser) {
context = {};
var getterFactory = new DynamicFieldGetterFactory();
changeDetector = new DirtyCheckingChangeDetector(getterFactory);
watchGrp = new RootWatchGroup(getterFactory, changeDetector, context);
logger = _logger;
parser = _parser;
astParser = _astParser;
}));
});

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

Expand Down Expand Up @@ -64,13 +64,13 @@ void main() {
expect(logger).toEqual(list);
}

beforeEach(inject((Logger _logger) {
beforeEach((Logger _logger) {
context = {};
var getterFactory = new DynamicFieldGetterFactory();
changeDetector = new DirtyCheckingChangeDetector(getterFactory);
watchGrp = new RootWatchGroup(getterFactory, changeDetector, context);
logger = _logger;
}));
});

it('should have a toString for debugging', () {
watchGrp.watch(parse('a'), (v, p) {});
Expand Down
71 changes: 35 additions & 36 deletions test/core/scope_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ void main() {


it('should skip scopes which dont have given event',
inject((RootScope rootScope, Logger log) {
(RootScope rootScope, Logger log) {
var child1 = rootScope.createChild('A');
rootScope.createChild('A1');
rootScope.createChild('A2');
Expand All @@ -663,7 +663,7 @@ void main() {
child2.on('event').listen((e) => log(e.data));
rootScope.broadcast('event', 'OK');
expect(log).toEqual(['OK']);
}));
});
});


Expand Down Expand Up @@ -847,14 +847,14 @@ void main() {
});


it(r'should execute and return value and update', inject(
(RootScope rootScope, ExceptionHandler e) {
LoggingExceptionHandler exceptionHandler = e;
rootScope.context['name'] = 'abc';
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
expect(log).toEqual('digest;digest;');
exceptionHandler.assertEmpty();
}));
it(r'should execute and return value and update',
(RootScope rootScope, ExceptionHandler e) {
LoggingExceptionHandler exceptionHandler = e;
rootScope.context['name'] = 'abc';
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
expect(log).toEqual('digest;digest;');
exceptionHandler.assertEmpty();
});


it(r'should execute and return value and update', (RootScope rootScope) {
Expand Down Expand Up @@ -924,14 +924,14 @@ void main() {
exceptionHandler.assertEmpty();
});

it(r'should execute and return value and update', inject(
(RootScope rootScope, ExceptionHandler e) {
LoggingExceptionHandler exceptionHandler = e;
rootScope.context['name'] = 'abc';
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
expect(log).toEqual('digest;digest;');
exceptionHandler.assertEmpty();
}));
it(r'should execute and return value and update',
(RootScope rootScope, ExceptionHandler e) {
LoggingExceptionHandler exceptionHandler = e;
rootScope.context['name'] = 'abc';
expect(rootScope.apply((context) => context['name'])).toEqual('abc');
expect(log).toEqual('digest;digest;');
exceptionHandler.assertEmpty();
});

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


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

rootScope.context['log'] = log;
rootScope.context['log'] = log;

rootScope.watch("log.add('r')", (_, __) => null);
childA.watch("log.add('a')", (_, __) => null);
childB.watch("log.add('b')", (_, __) => null);
rootScope.watch("log.add('r')", (_, __) => null);
childA.watch("log.add('a')", (_, __) => null);
childB.watch("log.add('b')", (_, __) => null);

// init
rootScope.digest();
expect(log.join('')).toEqual('rabrab');
}));
// init
rootScope.digest();
expect(log.join('')).toEqual('rabrab');
});


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


it(r'should return a function that allows listeners to be unregistered', inject(
it(r'should return a function that allows listeners to be unregistered',
(RootScope rootScope) {
var listener = guinness.createSpy('watch listener');
var watch;
Expand All @@ -1185,7 +1184,7 @@ void main() {
watch.remove();
rootScope.digest(); //trigger
expect(listener).not.toHaveBeenCalled();
}));
});


it(r'should be possible to remove every watch',
Expand Down Expand Up @@ -1242,7 +1241,7 @@ void main() {


it(r'should always call the watchr with newVal and oldVal equal on the first run',
inject((RootScope rootScope) {
(RootScope rootScope) {
var log = [];
var logger = (newVal, oldVal) {
var val = (newVal == oldVal || (newVal != oldVal && oldVal != newVal)) ? newVal : 'xxx';
Expand All @@ -1267,7 +1266,7 @@ void main() {
log = [];
rootScope.digest();
expect(log).toEqual([]);
}));
});


it('should properly watch constants', (RootScope rootScope, Logger log) {
Expand Down
Loading