redoc/lib/components/JsonSchema/json-schema-lazy.spec.ts

64 lines
1.6 KiB
TypeScript
Raw Normal View History

'use strict';
2016-06-12 20:44:34 +03:00
import { getChildDebugElement } from '../../../tests/helpers';
2016-07-01 15:53:16 +03:00
import { Component } from '@angular/core';
import {
inject,
2016-07-01 15:53:16 +03:00
TestComponentBuilder
2016-05-06 00:48:41 +03:00
} from '@angular/core/testing';
2016-06-12 20:44:34 +03:00
import { JsonSchemaLazy } from './json-schema-lazy';
describe('Redoc components', () => {
describe('JsonSchemaLazy Component', () => {
let builder;
let component;
let fixture;
2016-07-01 15:53:16 +03:00
beforeEach(inject([TestComponentBuilder], (tcb) => {
builder = tcb;
}));
2016-07-01 15:53:16 +03:00
beforeEach(() => {
fixture = builder.createSync(TestAppComponent);
let debugEl = getChildDebugElement(fixture.debugElement, 'json-schema-lazy');
component = <JsonSchemaLazy>debugEl.componentInstance;
spyOn(component, '_loadAfterSelf').and.stub();
});
afterEach(() => {
component._loadAfterSelf.and.callThrough();
});
it('should init component', () => {
expect(component).not.toBeNull();
});
it('should run loadNextToLocation on load', () => {
component.pointer = '#/def';
fixture.detectChanges();
component.load();
2016-06-29 19:06:42 +03:00
expect(component._loadAfterSelf).toHaveBeenCalled();
});
it('should not run loadNextToLocation if already loaded', () => {
component.pointer = '#/def';
fixture.detectChanges();
component.load();
component.load();
2016-06-29 19:06:42 +03:00
expect(component._loadAfterSelf.calls.count()).toEqual(1);
});
});
});
/** Test component that contains a Method. */
@Component({
selector: 'test-app',
directives: [JsonSchemaLazy],
template:
`<json-schema-lazy></json-schema-lazy>`
})
2016-06-13 20:54:24 +03:00
class TestAppComponent {
}