Вы не можете изменить шрифт Object Explorer на своем собственном , но вы можете его изменить.
В идеале вы должны initializeData()
вернуть обещание, которое оно создает, чтобы вы могли легко ждать, пока оно разрешится в ваших тестах. Тогда вместо того, чтобы пытаться выяснить, когда обещание разрешается, вы можете просто высмеять initializeData()
перед созданием класса.
Учитывая, что метод initializeData()
изменен для возврата обещания, вы можете проверить класс SimpleDataStore
следующим образом:
describe('SimpleDataStore', function () {
beforeEach(function () {
this.initializeData = spyOn(SimpleDataStore.prototype, 'initializeData');
this.http = jasmine.createSpyObj('HttpClient', ['get']);
this.storage = jasmine.createSpyObj('Storage', ['get']);
this.dataStore = new SimpleDataStore(this.http, this.storage);
// initializeData is called immediately upon construction.
expect(this.initializeData).toHaveBeenCalled();
});
describe('initializeData', function () {
beforeEach(function () {
// The data store is initialized, we can now let the calls go to the real implementation.
this.initializeData.and.callThrough();
});
afterEach(function () {
expect(this.storage.get).toHaveBeenCalledWith('dataKey');
});
it('is initialized with "dataKey" storage', function (done) {
const data = {};
this.storage.get.and.returnValue(Promise.resolve(data));
this.dataStore.initializeData()
.then(() => expect(this.dataStore._data.getValue()).toBe(data))
.catch(fail)
.finally(done)
});
it('is initialized with empty array when "dataKey" storage rejects', function (done) {
this.storage.get.and.returnValue(Promise.reject());
this.dataStore.initializeData()
.then(() => expect(this.dataStore._data.getValue()).toEqual([]))
.catch(fail)
.finally(done)
});
});
});