Skip to content
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
2 changes: 2 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -644,6 +644,8 @@ gulp.task('test.transpiler.unittest', function(done) {
runJasmineTests(['tools/transpiler/unittest/**/*.js'], done);
});

gulp.task('test.dart.angular2_test', shell.task(['pub run test -p dartium,firefox'], {'cwd': 'dist/dart/angular2_test'}));

// -----------------
// Pre/Post-test checks

Expand Down
7 changes: 5 additions & 2 deletions modules/angular2/src/test_lib/test_injector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,11 @@ export class FunctionWithParamTokens {
this._fn = fn;
}

execute(injector: Injector): void {
/**
* Returns the value of the executed function.
*/
execute(injector: Injector): any {
var params = ListWrapper.map(this._tokens, (t) => injector.get(t));
FunctionWrapper.apply(this._fn, params);
return FunctionWrapper.apply(this._fn, params);
}
}
13 changes: 13 additions & 0 deletions modules_dart/angular2_test/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
To run

```
cd darttest
pub get
pub run test test/dart_test.dart -p dartium
```

Run compiled with

```
pub run test test/dart_test.dart -p chrome
```
10 changes: 10 additions & 0 deletions modules_dart/angular2_test/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
name: angular2_test
environment:
sdk: '>=1.10.0 <2.0.0'
dependencies:
angular2: '0.0.0'
dev_dependencies:
test: '^0.12.3'
dependency_overrides:
angular2:
path: ../../dist/dart/angular2
62 changes: 62 additions & 0 deletions modules_dart/angular2_test/test/dart_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Because Angular is using dart:html, we need these tests to run on an actual
// browser. This means that it should be run with `-p dartium` or `-p chrome`.
@TestOn("browser")
import "package:angular2/angular2.dart"
show Component, View, NgFor, Injector, Key;

import 'package:angular2/src/dom/browser_adapter.dart'; // for BrowserDomAdapter
import 'package:angular2/src/reflection/reflection.dart'; // for reflector
import 'package:angular2/src/reflection/reflection_capabilities.dart'; // For ReflectionCapabilities

import 'package:angular2/src/test_lib/test_component_builder.dart';
import 'package:angular2/src/test_lib/test_injector.dart';

import "package:test/test.dart"; // Instead, import angular test lib?

// This is the component we will be testing.
@Component(selector: 'test-cmp')
@View(directives: const [NgFor])
class TestComponent {
List<num> items;
TestComponent() {
this.items = [1, 2];
}
}

const TEMPLATE =
"<div><copy-me template=\"ng-for #item of items\">{{item.toString()}};</copy-me></div>";

void main() {
Injector testInjector;

setUp(() {
BrowserDomAdapter.makeCurrent();
reflector.reflectionCapabilities = new ReflectionCapabilities();

testInjector = createTestInjector([]);
});

test("create a component using the TCB", () async {
await inject([TestComponentBuilder], (TestComponentBuilder tcb) async {
var rootTC = await tcb
.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent);

rootTC.detectChanges();
expect(rootTC.nativeElement.text, equals("1;2;"));
}).execute(testInjector);
});

test("should reflect added elements", () async {
await inject([TestComponentBuilder], (TestComponentBuilder tcb) async {
var rootTC = await tcb
.overrideTemplate(TestComponent, TEMPLATE)
.createAsync(TestComponent);

rootTC.detectChanges();
((rootTC.componentInstance.items as List<num>)).add(3);
rootTC.detectChanges();
expect(rootTC.nativeElement.text, equals("1;2;3;"));
}).execute(testInjector);
});
}
1 change: 1 addition & 0 deletions scripts/ci/test_server_dart.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,6 @@ trap killAllServers EXIT
# wait for server to come up!
sleep 3

./node_modules/.bin/gulp test.dart.angular2_test
./node_modules/.bin/gulp test.transpiler.unittest
./node_modules/.bin/gulp test.server.dart --browsers=$KARMA_BROWSERS