Updated tests after angular update

This commit is contained in:
Roman Hotsiy 2016-04-30 00:45:53 +03:00
parent 9d13b702b3
commit e8716ab69d
10 changed files with 52 additions and 42 deletions

View File

@ -46,6 +46,8 @@ module.exports = function (config) {
//load angular dependencies and browser polyfills //load angular dependencies and browser polyfills
files: [ files: [
'node_modules/zone.js/dist/zone.js', 'node_modules/zone.js/dist/zone.js',
'node_modules/zone.js/dist/fake-async-test.js',
'node_modules/zone.js/dist/async-test.js',
'node_modules/zone.js/dist/jasmine-patch.js', 'node_modules/zone.js/dist/jasmine-patch.js',
'node_modules/zone.js/dist/long-stack-trace-zone.js', 'node_modules/zone.js/dist/long-stack-trace-zone.js',
'node_modules/babel-polyfill/dist/polyfill.js', 'node_modules/babel-polyfill/dist/polyfill.js',

View File

@ -30,7 +30,7 @@ describe('Common components', () => {
builder.createAsync(TestApp).then(_fixture => { builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture; fixture = _fixture;
let debugEl = getChildDebugElementByType(fixture.debugElement, StickySidebar); let debugEl = getChildDebugElementByType(fixture.debugElement, StickySidebar);
component = debugEl.componentInstance; component = debugEl.injector.get(StickySidebar);
done(); done();
}, err => done.fail(err)); }, err => done.fail(err));
}); });

View File

@ -5,7 +5,8 @@ import {Component, provide} from 'angular2/core';
import { import {
TestComponentBuilder, TestComponentBuilder,
injectAsync, async,
inject,
beforeEach, beforeEach,
beforeEachProviders, beforeEachProviders,
it it
@ -26,10 +27,12 @@ describe('Redoc components', () => {
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(OptionsManager, {useValue: optsMgr}) provide(OptionsManager, {useValue: optsMgr})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/api-info-test.json').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/api-info-test.json');
})); })));
beforeEach((done) => { beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => { builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture; fixture = _fixture;

View File

@ -5,7 +5,8 @@ import {Component, provide} from 'angular2/core';
import { import {
TestComponentBuilder, TestComponentBuilder,
injectAsync, async,
inject,
beforeEach, beforeEach,
beforeEachProviders, beforeEachProviders,
it it
@ -26,11 +27,11 @@ describe('Redoc components', () => {
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}) provide(SchemaManager, {useValue: new SchemaManager()})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, _schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, _schemaMgr) => {
builder = tcb; builder = tcb;
schemaMgr = _schemaMgr; schemaMgr = _schemaMgr;
return schemaMgr.load(schemaUrl).then(() => null, (err) => { throw err; }); return schemaMgr.load(schemaUrl);
})); })));
beforeEach((done) => { beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => { builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture; fixture = _fixture;

View File

@ -6,7 +6,8 @@ import {BrowserDomAdapter} from 'angular2/platform/browser';
import { import {
TestComponentBuilder, TestComponentBuilder,
injectAsync, async,
inject,
beforeEach, beforeEach,
beforeEachProviders, beforeEachProviders,
it it
@ -25,10 +26,10 @@ describe('Redoc components', () => {
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}), provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}),
provide(OptionsManager, {useClass: OptionsManager}) provide(OptionsManager, {useClass: OptionsManager})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.yml').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/extended-petstore.yml');
})); })));
beforeEach((done) => { beforeEach((done) => {
builder.createAsync(TestApp).then(fixture => { builder.createAsync(TestApp).then(fixture => {
component = getChildDebugElement(fixture.debugElement, 'method').componentInstance; component = getChildDebugElement(fixture.debugElement, 'method').componentInstance;

View File

@ -7,7 +7,8 @@ import {BrowserDomAdapter} from 'angular2/platform/browser';
import { import {
TestComponentBuilder, TestComponentBuilder,
injectAsync, inject,
async,
beforeEach, beforeEach,
beforeEachProviders, beforeEachProviders,
it it
@ -26,10 +27,10 @@ describe('Redoc components', () => {
provide(OptionsManager, {useClass: OptionsManager}), provide(OptionsManager, {useClass: OptionsManager}),
provide(BrowserDomAdapter, {useClass: BrowserDomAdapter}) provide(BrowserDomAdapter, {useClass: BrowserDomAdapter})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/methods-list-component.json');
})); })));
beforeEach((done) => { beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => { builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture; fixture = _fixture;

View File

@ -66,7 +66,7 @@ export default class Redoc extends BaseComponent {
]; ];
if (Redoc.appRef) { if (Redoc.appRef) {
Redoc.dispose(); Redoc.destroy();
} }
Redoc.showLoadingAnimation(); Redoc.showLoadingAnimation();
return SchemaManager.instance().load(specUrl) return SchemaManager.instance().load(specUrl)
@ -102,7 +102,7 @@ export default class Redoc extends BaseComponent {
} }
} }
static dispose() { static destroy() {
let el = dom.query('redoc'); let el = dom.query('redoc');
let elClone; let elClone;
let parent; let parent;
@ -115,10 +115,10 @@ export default class Redoc extends BaseComponent {
elClone = el.cloneNode(false); elClone = el.cloneNode(false);
if (Redoc.appRef) { if (Redoc.appRef) {
Redoc.appRef.dispose(); Redoc.appRef.destroy();
Redoc.appRef = null; Redoc.appRef = null;
// Redoc dispose removes host element, so need to restore it // Redoc destroy removes host element, so need to restore it
elClone.innerHTML = 'Loading...'; elClone.innerHTML = 'Loading...';
parent && parent.insertBefore(elClone, nextSibling); parent && parent.insertBefore(elClone, nextSibling);
} }

View File

@ -6,7 +6,8 @@ import {BrowserDomAdapter} from 'angular2/platform/browser';
import { import {
TestComponentBuilder, TestComponentBuilder,
injectAsync, inject,
async,
beforeEach, beforeEach,
beforeEachProviders, beforeEachProviders,
it it
@ -26,10 +27,10 @@ describe('Redoc components', () => {
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(OptionsManager, {useValue: optsMgr}) provide(OptionsManager, {useValue: optsMgr})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.yml').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/extended-petstore.yml');
})); })));
it('should init component', (done) => { it('should init component', (done) => {
@ -141,29 +142,29 @@ describe('Redoc components', () => {
}); });
}); });
describe('Redoc dispose', () => { describe('Redoc destroy', () => {
let builder; let builder;
let fixture; let fixture;
let element; let element;
let disposeSpy; let destroySpy;
let dom = new BrowserDomAdapter(); let dom = new BrowserDomAdapter();
beforeEachProviders(() => [ beforeEachProviders(() => [
provide(SchemaManager, {useValue: new SchemaManager()}), provide(SchemaManager, {useValue: new SchemaManager()}),
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(OptionsManager, {useValue: optsMgr}) provide(OptionsManager, {useValue: optsMgr})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/methods-list-component.json');
})); })));
beforeEach((done) => { beforeEach((done) => {
builder.createAsync(TestApp).then(_fixture => { builder.createAsync(TestApp).then(_fixture => {
fixture = _fixture; fixture = _fixture;
element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement; element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement;
disposeSpy = jasmine.createSpy('spy'); destroySpy = jasmine.createSpy('spy');
Redoc.appRef = { Redoc.appRef = {
dispose: disposeSpy destroy: destroySpy
}; };
fixture.detectChanges(); fixture.detectChanges();
done(); done();
@ -175,20 +176,20 @@ describe('Redoc components', () => {
Redoc.appRef = null; Redoc.appRef = null;
}); });
it('should call componentRef.dispose', () => { it('should call componentRef.destroy', () => {
Redoc.dispose(); Redoc.destroy();
expect(disposeSpy).toHaveBeenCalled(); expect(destroySpy).toHaveBeenCalled();
}); });
it('should create new host element', () => { it('should create new host element', () => {
element.parentElement.removeChild(element); element.parentElement.removeChild(element);
Redoc.dispose(); Redoc.destroy();
expect(dom.query('redoc')).not.toBeNull(); expect(dom.query('redoc')).not.toBeNull();
dom.query('redoc').should.not.be.equal(element); dom.query('redoc').should.not.be.equal(element);
}); });
it('should set to null appRef', () => { it('should set to null appRef', () => {
Redoc.dispose(); Redoc.destroy();
expect(Redoc.appRef).toBeNull(); expect(Redoc.appRef).toBeNull();
}); });
}); });

View File

@ -7,7 +7,8 @@ import OptionsManager from 'lib/options';
import { import {
TestComponentBuilder, TestComponentBuilder,
injectAsync, inject,
async,
beforeEach, beforeEach,
beforeEachProviders, beforeEachProviders,
it it
@ -34,10 +35,10 @@ describe('Redoc components', () => {
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}), provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
provide(OptionsManager, {useValue: testOptions}) provide(OptionsManager, {useValue: testOptions})
]); ]);
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => { beforeEach(async(inject([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
builder = tcb; builder = tcb;
return schemaMgr.load('/tests/schemas/extended-petstore.yml').then(() => null, (err) => { throw err; }); return schemaMgr.load('/tests/schemas/extended-petstore.yml');
})); })));
afterEach(() => { afterEach(() => {
if (fixture) fixture.destroy(); if (fixture) fixture.destroy();

View File

@ -105,6 +105,6 @@
"sinon": "^1.17.2", "sinon": "^1.17.2",
"systemjs-builder": "^0.15.2", "systemjs-builder": "^0.15.2",
"vinyl-paths": "^2.0.0", "vinyl-paths": "^2.0.0",
"zone.js": "^0.6.6" "zone.js": "^0.6.12"
} }
} }