2020-09-14 14:24:15 -04:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google LLC All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
2021-04-08 15:34:55 -04:00
|
|
|
import {installVirtualGitClientSpies} from '../../utils/testing';
|
2020-09-14 14:24:15 -04:00
|
|
|
import {BaseModule} from './base';
|
|
|
|
|
|
|
|
/** Data mocking as the "retrieved data". */
|
|
|
|
const exampleData = 'this is example data' as const;
|
|
|
|
|
|
|
|
/** A simple usage of the BaseModule to illustrate the workings built into the abstract class. */
|
|
|
|
class ConcreteBaseModule extends BaseModule<typeof exampleData> {
|
2021-07-07 13:58:22 -04:00
|
|
|
override async retrieveData() {
|
2020-09-14 14:24:15 -04:00
|
|
|
return exampleData;
|
|
|
|
}
|
2021-07-07 13:58:22 -04:00
|
|
|
override async printToTerminal() {}
|
2020-09-14 14:24:15 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
describe('BaseModule', () => {
|
|
|
|
let retrieveDataSpy: jasmine.Spy;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
retrieveDataSpy = spyOn(ConcreteBaseModule.prototype, 'retrieveData');
|
2021-04-08 15:34:55 -04:00
|
|
|
installVirtualGitClientSpies();
|
2020-09-14 14:24:15 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('begins retrieving data during construction', () => {
|
2021-04-08 15:34:55 -04:00
|
|
|
new ConcreteBaseModule({} as any);
|
2020-09-14 14:24:15 -04:00
|
|
|
|
|
|
|
expect(retrieveDataSpy).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('makes the data available via the data attribute', async () => {
|
|
|
|
retrieveDataSpy.and.callThrough();
|
2021-04-08 15:34:55 -04:00
|
|
|
const module = new ConcreteBaseModule({} as any);
|
2020-09-14 14:24:15 -04:00
|
|
|
|
|
|
|
expect(await module.data).toBe(exampleData);
|
|
|
|
});
|
|
|
|
});
|