Я пытаюсь протестировать класс, который использует метод статического класса. Так как я могу заглушить статический метод класса. Я хочу отобразить элемент в classUnderTest.tsx, но метод componentDidMount возвращает ошибку. TypeError: Невозможно прочитать свойство 'subscribe' из неопределенного
// This is the testFile.tsx
import * as NineZoneSampleApp from "../../../src/frontend/app/NineZoneSampleApp";
const state = {
sampleAppState: {
failures: _data ,
},
};
const store = {
getState() {
return state;
},
};
beforeEach(() => {
sinon.stub(NineZoneSampleApp, "NineZoneSampleApp").returns(() => store);
});
//Class code that I am testing, I want to test
// ClassUnderTest.tsx
NineZoneSampleApp.store.subscribe.
public componentDidMount() {
const unsubscribe = NineZoneSampleApp.store.subscribe(() => {
const state = NineZoneSampleApp.store.getState();
if (state.sampleAppState.failures && state.sampleAppState.failures.length > 0) {
this.state.dataProvider.setItems(this.getRows(state.sampleAppState.failures));
this.setState({ dataProvider: this.state.dataProvider, issues: state.sampleAppState.failures });
unsubscribe();
}
});
}
//This is the nineZoneSampleApp file
//it is a static file.and want to stub the below method(getter):
public static get store(): AppStore { return this._appState.store; }
при попытке запуститьthe test: TypeError: Невозможно прочитать свойство 'subscribe' из неопределенного