fix(aio): fix up typing errors in tests
The new version of Jasmine types identified issues with our unit tests.
This commit is contained in:
parent
faacbe4dac
commit
39f2977fa8
|
@ -54,7 +54,7 @@ describe('ApiService', () => {
|
||||||
|
|
||||||
describe('#sections', () => {
|
describe('#sections', () => {
|
||||||
it('first subscriber should fetch sections', () => {
|
it('first subscriber should fetch sections', () => {
|
||||||
const data = [{name: 'a'}, {name: 'b'}];
|
const data = [{name: 'a', title: 'A', items: []}, {name: 'b', title: 'B', items: []}];
|
||||||
|
|
||||||
service.sections.subscribe(sections => {
|
service.sections.subscribe(sections => {
|
||||||
expect(sections).toEqual(data);
|
expect(sections).toEqual(data);
|
||||||
|
@ -64,7 +64,7 @@ describe('ApiService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('second subscriber should get previous sections and NOT trigger refetch', () => {
|
it('second subscriber should get previous sections and NOT trigger refetch', () => {
|
||||||
const data = [{name: 'a'}, {name: 'b'}];
|
const data = [{name: 'a', title: 'A', items: []}, {name: 'b', title: 'B', items: []}];
|
||||||
let subscriptions = 0;
|
let subscriptions = 0;
|
||||||
|
|
||||||
service.sections.subscribe(sections => {
|
service.sections.subscribe(sections => {
|
||||||
|
@ -99,7 +99,7 @@ describe('ApiService', () => {
|
||||||
let connection: MockConnection;
|
let connection: MockConnection;
|
||||||
backend.connections.subscribe(c => connection = c);
|
backend.connections.subscribe(c => connection = c);
|
||||||
|
|
||||||
let data = [{name: 'a'}, {name: 'b'}];
|
let data = [{name: 'a', title: 'A', items: []}, {name: 'b', title: 'B', items: []}];
|
||||||
|
|
||||||
service.sections.subscribe(sections => {
|
service.sections.subscribe(sections => {
|
||||||
// called twice during this test
|
// called twice during this test
|
||||||
|
@ -110,7 +110,7 @@ describe('ApiService', () => {
|
||||||
connection.mockRespond(createResponse(data));
|
connection.mockRespond(createResponse(data));
|
||||||
|
|
||||||
// refresh/refetch
|
// refresh/refetch
|
||||||
data = [{name: 'c'}];
|
data = [{name: 'c', title: 'C', items: []}];
|
||||||
service.fetchSections();
|
service.fetchSections();
|
||||||
connection.mockRespond(createResponse(data));
|
connection.mockRespond(createResponse(data));
|
||||||
|
|
||||||
|
|
|
@ -87,7 +87,7 @@ describe('CodeExampleComponent', () => {
|
||||||
class TestCodeComponent {
|
class TestCodeComponent {
|
||||||
@Input() code = '';
|
@Input() code = '';
|
||||||
@Input() language: string;
|
@Input() language: string;
|
||||||
@Input() linenums: boolean | number;
|
@Input() linenums: string;
|
||||||
@Input() path: string;
|
@Input() path: string;
|
||||||
@Input() region: string;
|
@Input() region: string;
|
||||||
@Input() hideCopy: boolean;
|
@Input() hideCopy: boolean;
|
||||||
|
|
|
@ -26,7 +26,7 @@ export class CodeExampleComponent implements OnInit {
|
||||||
classes: {};
|
classes: {};
|
||||||
code: string;
|
code: string;
|
||||||
language: string;
|
language: string;
|
||||||
linenums: boolean | number;
|
linenums: string;
|
||||||
path: string;
|
path: string;
|
||||||
region: string;
|
region: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
@ -36,7 +36,7 @@ export class CodeExampleComponent implements OnInit {
|
||||||
isAvoid = false;
|
isAvoid = false;
|
||||||
|
|
||||||
constructor(private elementRef: ElementRef) {
|
constructor(private elementRef: ElementRef) {
|
||||||
const element = this.elementRef.nativeElement;
|
const element: HTMLElement = this.elementRef.nativeElement;
|
||||||
|
|
||||||
this.language = element.getAttribute('language') || '';
|
this.language = element.getAttribute('language') || '';
|
||||||
this.linenums = element.getAttribute('linenums');
|
this.linenums = element.getAttribute('linenums');
|
||||||
|
|
|
@ -24,7 +24,7 @@ export interface NavigationViews {
|
||||||
*/
|
*/
|
||||||
export interface CurrentNode {
|
export interface CurrentNode {
|
||||||
url: string;
|
url: string;
|
||||||
view: 'SideNav' | 'TopBar' | 'Footer';
|
view: string;
|
||||||
nodes: NavigationNode[];
|
nodes: NavigationNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -91,7 +91,7 @@ describe('NavigationService', () => {
|
||||||
];
|
];
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
navService.navigationViews.subscribe(views => view = views.sideNav);
|
navService.navigationViews.subscribe(views => view = views['sideNav']);
|
||||||
backend.connectionsArray[0].mockRespond(createResponse({sideNav}));
|
backend.connectionsArray[0].mockRespond(createResponse({sideNav}));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ describe('NavigationService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should ignore trailing slashes, hashes, and search params on URLs in the navmap', () => {
|
it('should ignore trailing slashes, hashes, and search params on URLs in the navmap', () => {
|
||||||
const cnode = {
|
const cnode: CurrentNode = {
|
||||||
url: 'c',
|
url: 'c',
|
||||||
view: 'SideNav',
|
view: 'SideNav',
|
||||||
nodes: [
|
nodes: [
|
||||||
|
@ -216,17 +216,18 @@ describe('NavigationService', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('versionInfo', () => {
|
describe('versionInfo', () => {
|
||||||
|
const expectedVersionInfo = { raw: '4.0.0' } as VersionInfo;
|
||||||
let versionInfo: VersionInfo;
|
let versionInfo: VersionInfo;
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
navService.versionInfo.subscribe(info => versionInfo = info);
|
navService.versionInfo.subscribe(info => versionInfo = info);
|
||||||
backend.connectionsArray[0].mockRespond(createResponse({
|
backend.connectionsArray[0].mockRespond(createResponse({
|
||||||
__versionInfo: { raw: '4.0.0' }
|
__versionInfo: expectedVersionInfo
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should extract the version info', () => {
|
it('should extract the version info', () => {
|
||||||
expect(versionInfo).toEqual({ raw: '4.0.0' });
|
expect(versionInfo).toEqual(expectedVersionInfo);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -246,7 +247,7 @@ describe('NavigationService', () => {
|
||||||
{...v, ...{ tooltip: v.title + '.'}})
|
{...v, ...{ tooltip: v.title + '.'}})
|
||||||
);
|
);
|
||||||
|
|
||||||
navService.navigationViews.subscribe(views => actualDocVersions = views.docVersions);
|
navService.navigationViews.subscribe(views => actualDocVersions = views['docVersions']);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should extract the docVersions', () => {
|
it('should extract the docVersions', () => {
|
||||||
|
|
|
@ -278,7 +278,7 @@ describe('LocationService', () => {
|
||||||
|
|
||||||
service.go(testUrl);
|
service.go(testUrl);
|
||||||
expect(url).toEqual(initialUrl, 'should not have re-navigated locally');
|
expect(url).toEqual(initialUrl, 'should not have re-navigated locally');
|
||||||
expect(goExternalSpy.wasCalled).toBeFalsy('should not have navigated externally');
|
expect(goExternalSpy).not.toHaveBeenCalled();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,6 +32,8 @@ describe('TocService', () => {
|
||||||
|
|
||||||
describe('tocList', () => {
|
describe('tocList', () => {
|
||||||
it('should emit the latest value to new subscribers', () => {
|
it('should emit the latest value to new subscribers', () => {
|
||||||
|
const expectedValue1 = {} as TocItem;
|
||||||
|
const expectedValue2 = {} as TocItem;
|
||||||
let value1: TocItem[];
|
let value1: TocItem[];
|
||||||
let value2: TocItem[];
|
let value2: TocItem[];
|
||||||
|
|
||||||
|
@ -39,21 +41,23 @@ describe('TocService', () => {
|
||||||
tocService.tocList.subscribe(v => value1 = v);
|
tocService.tocList.subscribe(v => value1 = v);
|
||||||
expect(value1).toEqual([]);
|
expect(value1).toEqual([]);
|
||||||
|
|
||||||
tocService.tocList.next([{}, {}] as TocItem[]);
|
tocService.tocList.next([expectedValue1, expectedValue2] as TocItem[]);
|
||||||
tocService.tocList.subscribe(v => value2 = v);
|
tocService.tocList.subscribe(v => value2 = v);
|
||||||
expect(value2).toEqual([{}, {}]);
|
expect(value2).toEqual([expectedValue1, expectedValue2]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit the same values to all subscribers', () => {
|
it('should emit the same values to all subscribers', () => {
|
||||||
|
const expectedValue1 = {} as TocItem;
|
||||||
|
const expectedValue2 = {} as TocItem;
|
||||||
const emittedValues: TocItem[][] = [];
|
const emittedValues: TocItem[][] = [];
|
||||||
|
|
||||||
tocService.tocList.subscribe(v => emittedValues.push(v));
|
tocService.tocList.subscribe(v => emittedValues.push(v));
|
||||||
tocService.tocList.subscribe(v => emittedValues.push(v));
|
tocService.tocList.subscribe(v => emittedValues.push(v));
|
||||||
tocService.tocList.next([{ title: 'A' }, { title: 'B' }] as TocItem[]);
|
tocService.tocList.next([expectedValue1, expectedValue2] as TocItem[]);
|
||||||
|
|
||||||
expect(emittedValues).toEqual([
|
expect(emittedValues).toEqual([
|
||||||
[{ title: 'A' }, { title: 'B' }],
|
[expectedValue1, expectedValue2],
|
||||||
[{ title: 'A' }, { title: 'B' }]
|
[expectedValue1, expectedValue2]
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue