\n ')})
+ class MyComp {
}
- }
- }
- TestBed.configureTestingModule({declarations: [SomeDir]});
- let error: any;
- try {
- compileAndCreateComponent(MyComp);
- } catch (e) {
- error = e;
- }
- // The error should be logged from the 2nd-element
- expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
- line: 1,
- column: 19,
- source: ngUrl,
- });
- }));
+ expect(() => compileAndCreateComponent(MyComp))
+ .toThrowError(new RegExp(
+ `Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:2`));
+ }));
- fixmeIvy('unknown').it(
- 'should report source location for binding errors', fakeAsync(() => {
- const template = `
`;
+ fixmeIvy('FW-682: Compiler error handling')
+ .it('should use the right source url in template parse errors', fakeAsync(() => {
+ @Component({...templateDecorator('
\n
')})
+ class MyComp {
+ }
- @Component({...templateDecorator(template)})
- class MyComp {
- createError() { throw new Error('Test'); }
- }
+ expect(() => compileAndCreateComponent(MyComp))
+ .toThrowError(new RegExp(
+ `Template parse errors[\\s\\S]*${ngUrl.replace('$', '\\$')}@1:7`));
+ }));
- const comp = compileAndCreateComponent(MyComp);
+ fixmeIvy('FW-223: Generate source maps during template compilation')
+ .it('should create a sourceMap for templates', fakeAsync(() => {
+ const template = `Hello World!`;
- let error: any;
- try {
- comp.detectChanges();
- } catch (e) {
- error = e;
- }
- // the stack should point to the binding
- expect(getSourcePositionForStack(error.stack)).toEqual({
- line: 2,
- column: 12,
- source: ngUrl,
- });
- // The error should be logged from the element
- expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
- line: 2,
- column: 4,
- source: ngUrl,
- });
- }));
+ @Component({...templateDecorator(template)})
+ class MyComp {
+ }
- fixmeIvy('unknown').it(
- 'should report source location for event errors', fakeAsync(() => {
- const template = `
\n
`;
+ compileAndCreateComponent(MyComp);
- @Component({...templateDecorator(template)})
- class MyComp {
- createError() { throw new Error('Test'); }
- }
+ const sourceMap = getSourceMap('ng:///DynamicTestModule/MyComp.ngfactory.js');
+ expect(sourceMap.sources).toEqual([
+ 'ng:///DynamicTestModule/MyComp.ngfactory.js', ngUrl
+ ]);
+ expect(sourceMap.sourcesContent).toEqual([' ', template]);
+ }));
- const comp = compileAndCreateComponent(MyComp);
- let error: any;
- const errorHandler = TestBed.get(ErrorHandler);
- spyOn(errorHandler, 'handleError').and.callFake((e: any) => error = e);
- comp.debugElement.children[0].children[0].triggerEventHandler('click', 'EVENT');
- expect(error).toBeTruthy();
- // the stack should point to the binding
- expect(getSourcePositionForStack(error.stack)).toEqual({
- line: 2,
- column: 12,
- source: ngUrl,
- });
- // The error should be logged from the element
- expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
- line: 2,
- column: 4,
- source: ngUrl,
- });
+ fixmeIvy('FW-223: Generate source maps during template compilation')
+ .it('should report source location for di errors', fakeAsync(() => {
+ const template = `
`;
- }));
+ @Component({...templateDecorator(template)})
+ class MyComp {
+ }
+
+ @Directive({selector: '[someDir]'})
+ class SomeDir {
+ constructor() { throw new Error('Test'); }
+ }
+
+ TestBed.configureTestingModule({declarations: [SomeDir]});
+ let error: any;
+ try {
+ compileAndCreateComponent(MyComp);
+ } catch (e) {
+ error = e;
+ }
+ // The error should be logged from the element
+ expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
+ line: 2,
+ column: 4,
+ source: ngUrl,
+ });
+ }));
+
+ fixmeIvy('FW-223: Generate source maps during template compilation')
+ .it('should report di errors with multiple elements and directives', fakeAsync(() => {
+ const template = `
`;
+
+ @Component({...templateDecorator(template)})
+ class MyComp {
+ }
+
+ @Directive({selector: '[someDir]'})
+ class SomeDir {
+ constructor(@Attribute('someDir') someDir: string) {
+ if (someDir === 'throw') {
+ throw new Error('Test');
+ }
+ }
+ }
+
+ TestBed.configureTestingModule({declarations: [SomeDir]});
+ let error: any;
+ try {
+ compileAndCreateComponent(MyComp);
+ } catch (e) {
+ error = e;
+ }
+ // The error should be logged from the 2nd-element
+ expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
+ line: 1,
+ column: 19,
+ source: ngUrl,
+ });
+ }));
+
+ fixmeIvy('FW-223: Generate source maps during template compilation')
+ .it('should report source location for binding errors', fakeAsync(() => {
+ const template = `
\n
`;
+
+ @Component({...templateDecorator(template)})
+ class MyComp {
+ createError() { throw new Error('Test'); }
+ }
+
+ const comp = compileAndCreateComponent(MyComp);
+
+ let error: any;
+ try {
+ comp.detectChanges();
+ } catch (e) {
+ error = e;
+ }
+ // the stack should point to the binding
+ expect(getSourcePositionForStack(error.stack)).toEqual({
+ line: 2,
+ column: 12,
+ source: ngUrl,
+ });
+ // The error should be logged from the element
+ expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
+ line: 2,
+ column: 4,
+ source: ngUrl,
+ });
+ }));
+
+ fixmeIvy('FW-223: Generate source maps during template compilation')
+ .it('should report source location for event errors', fakeAsync(() => {
+ const template = `
\n
`;
+
+ @Component({...templateDecorator(template)})
+ class MyComp {
+ createError() { throw new Error('Test'); }
+ }
+
+ const comp = compileAndCreateComponent(MyComp);
+
+ let error: any;
+ const errorHandler = TestBed.get(ErrorHandler);
+ spyOn(errorHandler, 'handleError').and.callFake((e: any) => error = e);
+ comp.debugElement.children[0].children[0].triggerEventHandler('click', 'EVENT');
+ expect(error).toBeTruthy();
+ // the stack should point to the binding
+ expect(getSourcePositionForStack(error.stack)).toEqual({
+ line: 2,
+ column: 12,
+ source: ngUrl,
+ });
+ // The error should be logged from the element
+ expect(getSourcePositionForStack(getErrorLoggerStack(error))).toEqual({
+ line: 2,
+ column: 4,
+ source: ngUrl,
+ });
+
+ }));
}
});
}