chore(transformer): add a test that generated change detectors dont call notifyOnBinding for template variables
This commit is contained in:
parent
b3a763a718
commit
4bdc91892a
@ -1248,7 +1248,8 @@ export function main() {
|
|||||||
if (!IS_DARTIUM) {
|
if (!IS_DARTIUM) {
|
||||||
describe('Missing property bindings', () => {
|
describe('Missing property bindings', () => {
|
||||||
it('should throw on bindings to unknown properties',
|
it('should throw on bindings to unknown properties',
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
|
||||||
|
async) => {
|
||||||
tcb =
|
tcb =
|
||||||
tcb.overrideView(MyComp,
|
tcb.overrideView(MyComp,
|
||||||
new viewAnn.View({template: '<div unknown="{{ctxProp}}"></div>'}))
|
new viewAnn.View({template: '<div unknown="{{ctxProp}}"></div>'}))
|
||||||
@ -1262,7 +1263,8 @@ export function main() {
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
it('should not throw for property binding to a non-existing property when there is a matching directive property',
|
it('should not throw for property binding to a non-existing property when there is a matching directive property',
|
||||||
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder, async) => {
|
inject([TestComponentBuilder, AsyncTestCompleter], (tcb: TestComponentBuilder,
|
||||||
|
async) => {
|
||||||
tcb.overrideView(
|
tcb.overrideView(
|
||||||
MyComp,
|
MyComp,
|
||||||
new viewAnn.View(
|
new viewAnn.View(
|
||||||
|
@ -54,6 +54,18 @@ export function main() {
|
|||||||
`Can't bind to 'unknownProperty' since it isn't a know property of the 'some-custom' element and there are no matching directives with a corresponding property`);
|
`Can't bind to 'unknownProperty' since it isn't a know property of the 'some-custom' element and there are no matching directives with a corresponding property`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
describe('verification of properties', () => {
|
||||||
|
|
||||||
|
// TODO(tbosch): This is just a temporary test that makes sure that the dart server and
|
||||||
|
// dart browser is in sync. Change this to "not contains notifyBinding"
|
||||||
|
// when https://github.com/angular/angular/issues/3019 is solved.
|
||||||
|
it('should throw for unknown properties', () => {
|
||||||
|
builder.bindElement(el('<div/>')).bindProperty('unknownProperty', emptyExpr());
|
||||||
|
expect(() => builder.build()).not.toThrow();
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,109 +12,126 @@ import 'package:guinness/guinness.dart';
|
|||||||
import '../common/read_file.dart';
|
import '../common/read_file.dart';
|
||||||
|
|
||||||
var formatter = new DartFormatter();
|
var formatter = new DartFormatter();
|
||||||
|
AssetReader reader = new TestAssetReader();
|
||||||
|
|
||||||
main() => allTests();
|
main() => allTests();
|
||||||
|
|
||||||
void allTests() {
|
void allTests() {
|
||||||
Html5LibDomAdapter.makeCurrent();
|
Html5LibDomAdapter.makeCurrent();
|
||||||
AssetReader reader = new TestAssetReader();
|
|
||||||
|
|
||||||
beforeEach(() => setLogger(new PrintLogger()));
|
beforeEach(() => setLogger(new PrintLogger()));
|
||||||
|
|
||||||
describe('registrations', () {
|
describe('registrations', () {
|
||||||
Future<String> process(AssetId assetId) =>
|
noChangeDetectorTests();
|
||||||
processTemplates(reader, assetId, generateChangeDetectors: false);
|
changeDetectorTests();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
it('should parse simple expressions in inline templates.', () async {
|
void changeDetectorTests() {
|
||||||
var inputPath =
|
Future<String> process(AssetId assetId) => processTemplates(reader, assetId);
|
||||||
'template_compiler/inline_expression_files/hello.ng_deps.dart';
|
|
||||||
var expected = readFile(
|
|
||||||
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
|
|
||||||
var output = await process(new AssetId('a', inputPath));
|
|
||||||
_formatThenExpectEquals(output, expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should parse simple methods in inline templates.', () async {
|
// TODO(tbosch): This is just a temporary test that makes sure that the dart server and
|
||||||
var inputPath =
|
// dart browser is in sync. Change this to "not contains notifyBinding"
|
||||||
'template_compiler/inline_method_files/hello.ng_deps.dart';
|
// when https://github.com/angular/angular/issues/3019 is solved.
|
||||||
var expected = readFile(
|
it('shouldn always notifyBinding for template variables', () async {
|
||||||
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
|
var inputPath = 'template_compiler/ng_for_files/hello.ng_deps.dart';
|
||||||
var output = await process(new AssetId('a', inputPath));
|
var output = await(process(new AssetId('a', inputPath)));
|
||||||
_formatThenExpectEquals(output, expected);
|
expect(output).toContain('notifyOnBinding');
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
it('should parse simple expressions in linked templates.', () async {
|
void noChangeDetectorTests() {
|
||||||
var inputPath =
|
Future<String> process(AssetId assetId) =>
|
||||||
'template_compiler/url_expression_files/hello.ng_deps.dart';
|
processTemplates(reader, assetId, generateChangeDetectors: false);
|
||||||
var expected = readFile(
|
|
||||||
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
|
|
||||||
var output = await process(new AssetId('a', inputPath));
|
|
||||||
_formatThenExpectEquals(output, expected);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should parse simple methods in linked templates.', () async {
|
it('should parse simple expressions in inline templates.', () async {
|
||||||
var inputPath = 'template_compiler/url_method_files/hello.ng_deps.dart';
|
var inputPath =
|
||||||
var expected = readFile(
|
'template_compiler/inline_expression_files/hello.ng_deps.dart';
|
||||||
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
|
var expected = readFile(
|
||||||
var output = await process(new AssetId('a', inputPath));
|
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
|
||||||
_formatThenExpectEquals(output, expected);
|
var output = await process(new AssetId('a', inputPath));
|
||||||
});
|
_formatThenExpectEquals(output, expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('should not generated duplicate getters/setters', () async {
|
it('should parse simple methods in inline templates.', () async {
|
||||||
var inputPath = 'template_compiler/duplicate_files/hello.ng_deps.dart';
|
var inputPath =
|
||||||
var expected = readFile(
|
'template_compiler/inline_method_files/hello.ng_deps.dart';
|
||||||
'template_compiler/duplicate_files/expected/hello.ng_deps.dart');
|
var expected = readFile(
|
||||||
var output = await process(new AssetId('a', inputPath));
|
'template_compiler/inline_method_files/expected/hello.ng_deps.dart');
|
||||||
_formatThenExpectEquals(output, expected);
|
var output = await process(new AssetId('a', inputPath));
|
||||||
});
|
_formatThenExpectEquals(output, expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('should parse `View` directives with a single dependency.', () async {
|
it('should parse simple expressions in linked templates.', () async {
|
||||||
var inputPath =
|
var inputPath =
|
||||||
'template_compiler/one_directive_files/hello.ng_deps.dart';
|
'template_compiler/url_expression_files/hello.ng_deps.dart';
|
||||||
var expected = readFile(
|
var expected = readFile(
|
||||||
'template_compiler/one_directive_files/expected/hello.ng_deps.dart');
|
'template_compiler/url_expression_files/expected/hello.ng_deps.dart');
|
||||||
|
var output = await process(new AssetId('a', inputPath));
|
||||||
|
_formatThenExpectEquals(output, expected);
|
||||||
|
});
|
||||||
|
|
||||||
var output = await process(new AssetId('a', inputPath));
|
it('should parse simple methods in linked templates.', () async {
|
||||||
_formatThenExpectEquals(output, expected);
|
var inputPath = 'template_compiler/url_method_files/hello.ng_deps.dart';
|
||||||
});
|
var expected = readFile(
|
||||||
|
'template_compiler/url_method_files/expected/hello.ng_deps.dart');
|
||||||
|
var output = await process(new AssetId('a', inputPath));
|
||||||
|
_formatThenExpectEquals(output, expected);
|
||||||
|
});
|
||||||
|
|
||||||
it('should parse `View` directives with a single prefixed dependency.',
|
it('should not generated duplicate getters/setters', () async {
|
||||||
() async {
|
var inputPath = 'template_compiler/duplicate_files/hello.ng_deps.dart';
|
||||||
var inputPath = 'template_compiler/with_prefix_files/hello.ng_deps.dart';
|
var expected = readFile(
|
||||||
var expected = readFile(
|
'template_compiler/duplicate_files/expected/hello.ng_deps.dart');
|
||||||
'template_compiler/with_prefix_files/expected/hello.ng_deps.dart');
|
var output = await process(new AssetId('a', inputPath));
|
||||||
|
_formatThenExpectEquals(output, expected);
|
||||||
|
});
|
||||||
|
|
||||||
var output = await process(new AssetId('a', inputPath));
|
it('should parse `View` directives with a single dependency.', () async {
|
||||||
_formatThenExpectEquals(output, expected);
|
var inputPath =
|
||||||
|
'template_compiler/one_directive_files/hello.ng_deps.dart';
|
||||||
|
var expected = readFile(
|
||||||
|
'template_compiler/one_directive_files/expected/hello.ng_deps.dart');
|
||||||
|
|
||||||
inputPath = 'template_compiler/with_prefix_files/goodbye.ng_deps.dart';
|
var output = await process(new AssetId('a', inputPath));
|
||||||
expected = readFile(
|
_formatThenExpectEquals(output, expected);
|
||||||
'template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart');
|
});
|
||||||
|
|
||||||
output = await process(new AssetId('a', inputPath));
|
it('should parse `View` directives with a single prefixed dependency.',
|
||||||
_formatThenExpectEquals(output, expected);
|
() async {
|
||||||
});
|
var inputPath = 'template_compiler/with_prefix_files/hello.ng_deps.dart';
|
||||||
|
var expected = readFile(
|
||||||
|
'template_compiler/with_prefix_files/expected/hello.ng_deps.dart');
|
||||||
|
|
||||||
it('should parse angular directives with a prefix', () async {
|
var output = await process(new AssetId('a', inputPath));
|
||||||
var inputPath =
|
_formatThenExpectEquals(output, expected);
|
||||||
'template_compiler/with_prefix_files/ng2_prefix.ng_deps.dart';
|
|
||||||
var expected = readFile(
|
|
||||||
'template_compiler/with_prefix_files/expected/ng2_prefix.ng_deps.dart');
|
|
||||||
|
|
||||||
var output = await process(new AssetId('a', inputPath));
|
inputPath = 'template_compiler/with_prefix_files/goodbye.ng_deps.dart';
|
||||||
_formatThenExpectEquals(output, expected);
|
expected = readFile(
|
||||||
});
|
'template_compiler/with_prefix_files/expected/goodbye.ng_deps.dart');
|
||||||
|
|
||||||
it('should create the same output for multiple calls.', () async {
|
output = await process(new AssetId('a', inputPath));
|
||||||
var inputPath =
|
_formatThenExpectEquals(output, expected);
|
||||||
'template_compiler/inline_expression_files/hello.ng_deps.dart';
|
});
|
||||||
var expected = readFile(
|
|
||||||
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
|
it('should parse angular directives with a prefix', () async {
|
||||||
var output = await process(new AssetId('a', inputPath));
|
var inputPath =
|
||||||
_formatThenExpectEquals(output, expected);
|
'template_compiler/with_prefix_files/ng2_prefix.ng_deps.dart';
|
||||||
output = await process(new AssetId('a', inputPath));
|
var expected = readFile(
|
||||||
_formatThenExpectEquals(output, expected);
|
'template_compiler/with_prefix_files/expected/ng2_prefix.ng_deps.dart');
|
||||||
});
|
|
||||||
|
var output = await process(new AssetId('a', inputPath));
|
||||||
|
_formatThenExpectEquals(output, expected);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create the same output for multiple calls.', () async {
|
||||||
|
var inputPath =
|
||||||
|
'template_compiler/inline_expression_files/hello.ng_deps.dart';
|
||||||
|
var expected = readFile(
|
||||||
|
'template_compiler/inline_expression_files/expected/hello.ng_deps.dart');
|
||||||
|
var output = await process(new AssetId('a', inputPath));
|
||||||
|
_formatThenExpectEquals(output, expected);
|
||||||
|
output = await process(new AssetId('a', inputPath));
|
||||||
|
_formatThenExpectEquals(output, expected);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
library test.src.transform.template_compiler.ng_for_files.hello.ng_deps.dart;
|
||||||
|
|
||||||
|
import 'hello.dart';
|
||||||
|
import 'package:angular2/angular2.dart'
|
||||||
|
show bootstrap, Component, Directive, View, NgElement;
|
||||||
|
|
||||||
|
var _visited = false;
|
||||||
|
void initReflector(reflector) {
|
||||||
|
if (_visited) return;
|
||||||
|
_visited = true;
|
||||||
|
reflector
|
||||||
|
..registerType(HelloCmp, {
|
||||||
|
'factory': () => new HelloCmp(),
|
||||||
|
'parameters': const [const []],
|
||||||
|
'annotations': const [
|
||||||
|
const Component(selector: 'hello-app'),
|
||||||
|
const View(
|
||||||
|
template: '<li *ng-for="#thing of things"><div>test</div></li>',
|
||||||
|
directives: const [NgFor])
|
||||||
|
]
|
||||||
|
});
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"HelloCmp":
|
||||||
|
{
|
||||||
|
"id":"HelloCmp",
|
||||||
|
"selector":"hello-app",
|
||||||
|
"compileChildren":true,
|
||||||
|
"host":{},
|
||||||
|
"properties":[],
|
||||||
|
"readAttributes":[],
|
||||||
|
"type":1,
|
||||||
|
"version":1
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user