test(upgrade): reorganise test layout (#13812)

This commit is contained in:
Peter Bacon Darwin 2017-01-13 20:14:58 +00:00 committed by Miško Hevery
parent 5237b1c98c
commit 4dea347101
1 changed files with 110 additions and 108 deletions

View File

@ -18,51 +18,9 @@ export function main() {
beforeEach(() => destroyPlatform());
afterEach(() => destroyPlatform());
describe('(basic use)', () => {
it('should have angular 1 loaded', () => expect(angular.version.major).toBe(1));
describe('bootstrap errors', () => {
let adapter: UpgradeAdapter;
beforeEach(() => {
angular.module('ng1', []);
const ng2Component = Component({
selector: 'ng2',
template: `<BAD TEMPLATE div></div>`,
}).Class({constructor: function() {}});
const Ng2Module = NgModule({
declarations: [ng2Component],
imports: [BrowserModule],
}).Class({constructor: function() {}});
adapter = new UpgradeAdapter(Ng2Module);
});
it('should throw an uncaught error', fakeAsync(() => {
const resolveSpy = jasmine.createSpy('resolveSpy');
spyOn(console, 'error');
expect(() => {
adapter.bootstrap(html('<ng2></ng2>'), ['ng1']).ready(resolveSpy);
flushMicrotasks();
}).toThrowError();
expect(resolveSpy).not.toHaveBeenCalled();
}));
it('should output an error message to the console and re-throw', fakeAsync(() => {
let consoleErrorSpy: jasmine.Spy = spyOn(console, 'error');
expect(() => {
adapter.bootstrap(html('<ng2></ng2>'), ['ng1']);
flushMicrotasks();
}).toThrowError();
let args: any[] = consoleErrorSpy.calls.mostRecent().args;
expect(consoleErrorSpy).toHaveBeenCalled();
expect(args.length).toBeGreaterThan(0);
expect(args[0]).toEqual(jasmine.any(Error));
}));
});
it('should instantiate ng2 in ng1 template and project content', async(() => {
const ng1Module = angular.module('ng1', []);
@ -142,6 +100,50 @@ export function main() {
ref.dispose();
});
}));
});
describe('bootstrap errors', () => {
let adapter: UpgradeAdapter;
beforeEach(() => {
angular.module('ng1', []);
const ng2Component = Component({
selector: 'ng2',
template: `<BAD TEMPLATE div></div>`,
}).Class({constructor: function() {}});
const Ng2Module = NgModule({
declarations: [ng2Component],
imports: [BrowserModule],
}).Class({constructor: function() {}});
adapter = new UpgradeAdapter(Ng2Module);
});
it('should throw an uncaught error', fakeAsync(() => {
const resolveSpy = jasmine.createSpy('resolveSpy');
spyOn(console, 'error');
expect(() => {
adapter.bootstrap(html('<ng2></ng2>'), ['ng1']).ready(resolveSpy);
flushMicrotasks();
}).toThrowError();
expect(resolveSpy).not.toHaveBeenCalled();
}));
it('should output an error message to the console and re-throw', fakeAsync(() => {
const consoleErrorSpy: jasmine.Spy = spyOn(console, 'error');
expect(() => {
adapter.bootstrap(html('<ng2></ng2>'), ['ng1']);
flushMicrotasks();
}).toThrowError();
const args: any[] = consoleErrorSpy.calls.mostRecent().args;
expect(consoleErrorSpy).toHaveBeenCalled();
expect(args.length).toBeGreaterThan(0);
expect(args[0]).toEqual(jasmine.any(Error));
}));
});
describe('scope/component change-detection', () => {
it('should interleave scope and component expressions', async(() => {
@ -388,6 +390,31 @@ export function main() {
ref.dispose();
});
}));
it('should allow attribute selectors for components in ng2', async(() => {
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => MyNg2Module));
const ng1Module = angular.module('myExample', []);
@Component({selector: '[works]', template: 'works!'})
class WorksComponent {
}
@Component({selector: 'root-component', template: 'It <div works></div>'})
class RootComponent {
}
@NgModule({imports: [BrowserModule], declarations: [RootComponent, WorksComponent]})
class MyNg2Module {
}
ng1Module.directive('rootComponent', adapter.downgradeNg2Component(RootComponent));
document.body.innerHTML = '<root-component></root-component>';
adapter.bootstrap(document.body.firstElementChild, ['myExample']).ready((ref) => {
expect(multiTrim(document.body.textContent)).toEqual('It works!');
ref.dispose();
});
}));
});
describe('upgrade ng1 component', () => {
@ -1627,31 +1654,6 @@ export function main() {
}));
});
it('should allow attribute selectors for components in ng2', async(() => {
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => MyNg2Module));
const ng1Module = angular.module('myExample', []);
@Component({selector: '[works]', template: 'works!'})
class WorksComponent {
}
@Component({selector: 'root-component', template: 'It <div works></div>'})
class RootComponent {
}
@NgModule({imports: [BrowserModule], declarations: [RootComponent, WorksComponent]})
class MyNg2Module {
}
ng1Module.directive('rootComponent', adapter.downgradeNg2Component(RootComponent));
document.body.innerHTML = '<root-component></root-component>';
adapter.bootstrap(document.body.firstElementChild, ['myExample']).ready((ref) => {
expect(multiTrim(document.body.textContent)).toEqual('It works!');
ref.dispose();
});
}));
describe('examples', () => {
it('should verify UpgradeAdapter example', async(() => {
const adapter: UpgradeAdapter = new UpgradeAdapter(forwardRef(() => Ng2Module));