feat(DirectiveParser): throw errors when expected directives are not present
closes #527 Closes #570
This commit is contained in:

committed by
Misko Hevery

parent
715ee14ced
commit
94e203b9df
@ -1,5 +1,5 @@
|
||||
import {describe, beforeEach, it, expect, iit, ddescribe, el} from 'angular2/test_lib';
|
||||
import {isPresent} from 'angular2/src/facade/lang';
|
||||
import {isPresent, assertionsEnabled} from 'angular2/src/facade/lang';
|
||||
import {ListWrapper, MapWrapper, StringMapWrapper} from 'angular2/src/facade/collection';
|
||||
import {DirectiveParser} from 'angular2/src/core/compiler/pipeline/directive_parser';
|
||||
import {CompilePipeline} from 'angular2/src/core/compiler/pipeline/compile_pipeline';
|
||||
@ -85,20 +85,20 @@ export function main() {
|
||||
});
|
||||
|
||||
it('should not allow multiple component directives on the same element', () => {
|
||||
expect( () => {
|
||||
createPipeline().process(
|
||||
el('<div some-comp some-comp2></div>')
|
||||
);
|
||||
}).toThrowError('Only one component directive per element is allowed!');
|
||||
expect( () => {
|
||||
createPipeline().process(
|
||||
el('<div some-comp some-comp2></div>')
|
||||
);
|
||||
}).toThrowError('Multiple component directives not allowed on the same element - check <div some-comp some-comp2>');
|
||||
});
|
||||
|
||||
it('should not allow component directives on <template> elements', () => {
|
||||
expect( () => {
|
||||
createPipeline().process(
|
||||
el('<template some-comp></template>')
|
||||
);
|
||||
}).toThrowError('Only template directives are allowed on <template> elements!');
|
||||
});
|
||||
expect( () => {
|
||||
createPipeline().process(
|
||||
el('<template some-comp></template>')
|
||||
);
|
||||
}).toThrowError('Only template directives are allowed on template elements - check <template some-comp>');
|
||||
});
|
||||
});
|
||||
|
||||
describe('viewport directives', () => {
|
||||
@ -128,7 +128,7 @@ export function main() {
|
||||
createPipeline().process(
|
||||
el('<template some-templ some-templ2></template>')
|
||||
);
|
||||
}).toThrowError('Only one template directive per element is allowed!');
|
||||
}).toThrowError('Only one viewport directive can be used per element - check <template some-templ some-templ2>');
|
||||
});
|
||||
|
||||
it('should not allow viewport directives on non <template> elements', () => {
|
||||
@ -136,7 +136,8 @@ export function main() {
|
||||
createPipeline().process(
|
||||
el('<div some-templ></div>')
|
||||
);
|
||||
}).toThrowError('Viewport directives need to be placed on <template> elements or elements with template attribute!');
|
||||
|
||||
}).toThrowError('Viewport directives need to be placed on <template> elements or elements with template attribute - check <div some-templ>');
|
||||
});
|
||||
});
|
||||
|
||||
@ -172,14 +173,6 @@ export function main() {
|
||||
expect(results[0].decoratorDirectives).toEqual([reader.read(SomeDecorator)]);
|
||||
});
|
||||
|
||||
it('should not allow decorator directives on <template> elements', () => {
|
||||
expect( () => {
|
||||
createPipeline().process(
|
||||
el('<template some-decor></template>')
|
||||
);
|
||||
}).toThrowError('Only template directives are allowed on <template> elements!');
|
||||
});
|
||||
|
||||
it('should not instantiate decorator directive twice', () => {
|
||||
var pipeline = createPipeline({propertyBindings: {
|
||||
'some-decor-with-binding': 'someExpr'
|
||||
|
@ -76,7 +76,7 @@ export function main() {
|
||||
} else if (isPresent(parent)) {
|
||||
current.inheritedProtoView = parent.inheritedProtoView;
|
||||
}
|
||||
}), new ElementBinderBuilder(parser, null)
|
||||
}), new ElementBinderBuilder(parser)
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,7 @@ export function main() {
|
||||
function createPipeline(ignoreBindings = false) {
|
||||
return new CompilePipeline([
|
||||
new MockStep((parent, current, control) => { current.ignoreBindings = ignoreBindings; }),
|
||||
new PropertyBindingParser(new Parser(new Lexer()), null)]);
|
||||
new PropertyBindingParser(new Parser(new Lexer()))]);
|
||||
}
|
||||
|
||||
it('should not parse bindings when ignoreBindings is true', () => {
|
||||
|
@ -14,7 +14,7 @@ export function main() {
|
||||
return new CompilePipeline([
|
||||
new MockStep((parent, current, control) => { current.ignoreBindings = ignoreBindings; }),
|
||||
new IgnoreChildrenStep(),
|
||||
new TextInterpolationParser(new Parser(new Lexer()), null)
|
||||
new TextInterpolationParser(new Parser(new Lexer()))
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -11,7 +11,7 @@ export function main() {
|
||||
describe('ViewSplitter', () => {
|
||||
|
||||
function createPipeline() {
|
||||
return new CompilePipeline([new ViewSplitter(new Parser(new Lexer()), null)]);
|
||||
return new CompilePipeline([new ViewSplitter(new Parser(new Lexer()))]);
|
||||
}
|
||||
|
||||
it('should mark root elements as viewRoot', () => {
|
||||
@ -160,14 +160,14 @@ export function main() {
|
||||
expect( () => {
|
||||
var rootElement = el('<div><div *foo *bar="blah"></div></div>');
|
||||
createPipeline().process(rootElement);
|
||||
}).toThrowError('Only one template directive per element is allowed: foo and bar cannot be used simultaneously!');
|
||||
}).toThrowError('Only one template directive per element is allowed: foo and bar cannot be used simultaneously in <div *foo *bar="blah">');
|
||||
});
|
||||
|
||||
it('should not allow template and bang directives on the same element', () => {
|
||||
it('should not allow template and star directives on the same element', () => {
|
||||
expect( () => {
|
||||
var rootElement = el('<div><div *foo template="blah"></div></div>');
|
||||
var rootElement = el('<div><div *foo template="bar"></div></div>');
|
||||
createPipeline().process(rootElement);
|
||||
}).toThrowError('Only one template directive per element is allowed: blah and foo cannot be used simultaneously!');
|
||||
}).toThrowError('Only one template directive per element is allowed: bar and foo cannot be used simultaneously in <div *foo template="bar">');
|
||||
});
|
||||
|
||||
});
|
||||
|
Reference in New Issue
Block a user