mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
Redoc dispose testcase
This commit is contained in:
parent
bc9e62141b
commit
5f34a700a3
|
@ -106,16 +106,22 @@ export default class Redoc extends BaseComponent {
|
|||
static dispose() {
|
||||
let dom = new BrowserDomAdapter();
|
||||
let el = dom.query('redoc');
|
||||
let parent = el.parentElement;
|
||||
let nextSibling = el.nextElementSibling;
|
||||
let parent;
|
||||
let nextSibling;
|
||||
if (el) {
|
||||
parent = el.parentElement;
|
||||
nextSibling = el.nextElementSibling;
|
||||
}
|
||||
|
||||
Redoc.appRef && Redoc.appRef.dispose();
|
||||
Redoc.appRef = null;
|
||||
if (Redoc.appRef) {
|
||||
Redoc.appRef.dispose();
|
||||
Redoc.appRef = null;
|
||||
|
||||
// Redoc dispose removes host element, so need to restore it
|
||||
el = dom.createElement('redoc');
|
||||
el.innerText = 'Loading...';
|
||||
parent.insertBefore(el, nextSibling);
|
||||
// Redoc dispose removes host element, so need to restore it
|
||||
el = dom.createElement('redoc');
|
||||
el.innerText = 'Loading...';
|
||||
parent && parent.insertBefore(el, nextSibling);
|
||||
}
|
||||
}
|
||||
}
|
||||
Redoc.parameters = Redoc.parameters.concat([[OptionsManager], [ElementRef], [BrowserDomAdapter]]);
|
||||
|
|
|
@ -129,8 +129,59 @@ describe('Redoc init', () => {
|
|||
done.fail('Error handler should not been called');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('Redoc dispose', () => {
|
||||
let builder;
|
||||
let fixture;
|
||||
let element;
|
||||
let disposeSpy;
|
||||
let dom = new BrowserDomAdapter();
|
||||
beforeEachProviders(() => [
|
||||
provide(SchemaManager, {useValue: new SchemaManager()}),
|
||||
provide(BrowserDomAdapter, {useValue: new BrowserDomAdapter()}),
|
||||
provide(OptionsManager, {useValue: optsMgr})
|
||||
]);
|
||||
beforeEach(injectAsync([TestComponentBuilder, SchemaManager], (tcb, schemaMgr) => {
|
||||
builder = tcb;
|
||||
return schemaMgr.load('/tests/schemas/methods-list-component.json').then(() => null, (err) => { throw err; });
|
||||
}));
|
||||
|
||||
beforeEach((done) => {
|
||||
builder.createAsync(TestApp).then(_fixture => {
|
||||
fixture = _fixture;
|
||||
element = getChildDebugElement(fixture.debugElement, 'methods-list').nativeElement;
|
||||
disposeSpy = jasmine.createSpy('spy');
|
||||
Redoc.appRef = {
|
||||
dispose: disposeSpy
|
||||
};
|
||||
fixture.detectChanges();
|
||||
done();
|
||||
}, err => { throw err; });
|
||||
});
|
||||
|
||||
afterEach(()=> {
|
||||
fixture.destroy();
|
||||
Redoc.appRef = null;
|
||||
});
|
||||
|
||||
it('should call componentRef.dispose', () => {
|
||||
Redoc.dispose();
|
||||
expect(disposeSpy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should create new host element', () => {
|
||||
element.parentElement.removeChild(element);
|
||||
Redoc.dispose();
|
||||
expect(dom.query('redoc')).not.toBeNull();
|
||||
dom.query('redoc').should.not.be.equal(element);
|
||||
});
|
||||
|
||||
it('should set to null appRef', () => {
|
||||
Redoc.dispose();
|
||||
expect(Redoc.appRef).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
/** Test component that contains a Redoc. */
|
||||
@Component({selector: 'test-app'})
|
||||
|
|
Loading…
Reference in New Issue
Block a user