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

Commit

Permalink
feat(jasmine): beforeEachModule syntax and injectifying its
Browse files Browse the repository at this point in the history
Closes #727
  • Loading branch information
jbdeboer authored and mhevery committed Mar 14, 2014
1 parent b3cb81a commit 4019046
Show file tree
Hide file tree
Showing 29 changed files with 296 additions and 206 deletions.
18 changes: 16 additions & 2 deletions lib/mock/zone.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@ library angular.mock_zone;

import 'dart:async' as dart_async;

// async and sync are function compositions.
class FunctionComposition {
Function outer;
Function inner;

FunctionComposition(this.outer, this.inner);

call() => outer(inner)();
}

final _asyncQueue = <Function>[];
final _timerQueue = <_TimerSpec>[];
final _asyncErrors = [];
Expand Down Expand Up @@ -144,7 +154,9 @@ noMoreAsync() {
* ...
* }));
*/
async(Function fn) => () {
async(Function fn) => new FunctionComposition(_asyncOuter, fn);

_asyncOuter(Function fn) => () {
_noMoreAsync = false;
_asyncErrors.clear();
_timerQueue.clear();
Expand Down Expand Up @@ -191,7 +203,9 @@ _createTimer(Function fn, Duration duration, bool periodic) {
* Enforces synchronous code. Any calls to scheduleMicrotask inside of 'sync'
* will throw an exception.
*/
sync(Function fn) => () {
sync(Function fn) => new FunctionComposition(_syncOuter, fn);

_syncOuter(Function fn) => () {
_asyncErrors.clear();

dart_async.runZoned(fn, zoneSpecification: new dart_async.ZoneSpecification(
Expand Down
24 changes: 19 additions & 5 deletions test/_specs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import 'package:angular/angular.dart';
import 'package:angular/mock/module.dart';
import 'package:collection/wrappers.dart' show DelegatingList;

import 'jasmine_syntax.dart';
import 'jasmine_syntax.dart' as jasmine_syntax;

export 'dart:html';
export 'jasmine_syntax.dart' hide main;
export 'package:unittest/unittest.dart';
export 'package:unittest/mock.dart';
export 'package:di/dynamic_injector.dart';
Expand Down Expand Up @@ -246,9 +245,24 @@ class JQuery extends DelegatingList<Node> {
shadowRoot() => new JQuery((this[0] as Element).shadowRoot);
}

// Jasmine syntax
_injectify(fn) => fn is FunctionComposition ? fn.outer(inject(fn.inner)) : inject(fn);
beforeEachModule(fn) => jasmine_syntax.beforeEach(module(fn), priority:1);

beforeEach(fn) => jasmine_syntax.beforeEach(_injectify(fn));
afterEach(fn) => jasmine_syntax.afterEach(_injectify(fn));
it(name, fn) => jasmine_syntax.it(name, _injectify(fn));
iit(name, fn) => jasmine_syntax.iit(name, _injectify(fn));
xit(name, fn) => jasmine_syntax.xit(name, fn);
xdescribe(name, fn) => jasmine_syntax.xdescribe(name, fn);
ddescribe(name, fn) => jasmine_syntax.ddescribe(name, fn);
describe(name, fn) => jasmine_syntax.describe(name, fn);

var jasmine = jasmine_syntax.jasmine;


main() {
beforeEach(setUpInjector);
beforeEach(() => wrapFn(sync));
afterEach(tearDownInjector);
jasmine_syntax.wrapFn(sync);
jasmine_syntax.beforeEach(setUpInjector, priority:3);
jasmine_syntax.afterEach(tearDownInjector);
}
2 changes: 1 addition & 1 deletion test/animate/animation_loop_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,4 @@ class MockAnimationFrame implements AnimationFrame {
completer.complete(time);
}
}
}
}
4 changes: 2 additions & 2 deletions test/core/core_directive_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import '../_specs.dart';
void main() {
describe('DirectiveMap', () {

beforeEach(module((Module module) {
beforeEachModule((Module module) {
module..type(AnnotatedIoComponent);
}));
});

it('should extract attr map from annotated component', inject((DirectiveMap directives) {
var annotations = directives.annotationsFor(AnnotatedIoComponent);
Expand Down
4 changes: 2 additions & 2 deletions test/core/parser/generated_getter_setter_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ import 'generated_getter_setter.dart';

main() {
describe('hybrid getter-setter', () {
beforeEach(module((Module module) {
beforeEachModule((Module module) {
module.type(Parser, implementedBy: DynamicParser);
module.type(ClosureMap, implementedBy: StaticClosureMap);
}));
});
parser_spec.main();
});
}
4 changes: 2 additions & 2 deletions test/core/parser/generated_parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ class AlwaysThrowError implements DynamicParser {

main() {
describe('generated parser', () {
beforeEach(module((Module module) {
beforeEachModule((Module module) {
module.type(Parser, implementedBy: StaticParser);
module.type(DynamicParser, implementedBy: AlwaysThrowError);

module.factory(StaticParserFunctions, (Injector injector) {
return generated_functions.functions();
});
}));
});
parser_spec.main();
});
}
4 changes: 2 additions & 2 deletions test/core/parser/parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,10 @@ main() {
Map<String, dynamic> context;
Parser<Expression> parser;
FilterMap filters;
beforeEach(module((Module module) {
beforeEachModule((Module module) {
module.type(IncrementFilter);
module.type(SubstringFilter);
}));
});
beforeEach(inject((Parser injectedParser, FilterMap injectedFilters) {
parser = injectedParser;
filters = injectedFilters;
Expand Down
4 changes: 2 additions & 2 deletions test/core/parser/static_parser_spec.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class AlwaysReturnX implements DynamicParser {

main() {
describe('static parser', () {
beforeEach(module((Module m) {
beforeEachModule((Module m) {
m.type(Parser, implementedBy: StaticParser);
m.type(DynamicParser, implementedBy: AlwaysReturnX);
m.value(StaticParserFunctions, new StaticParserFunctions(EVAL, ASSIGN));
}));
});


it('should run a static function', inject((Parser parser) {
Expand Down
Loading

0 comments on commit 4019046

Please sign in to comment.