Вот ситуация, когда у меня есть компонент React, который захватывает все записи через разбиение на страницы в componentDidUpdate. Код работает так, как задумано, но я не могу получить инструкции ожидания для ожидания завершения всех асинхронных операций.
Код компонента
async componentDidUpdate(prevProps) {
if (this.props !== prevProps) {
console.info('Componet did update called');
//File ids are grabbed else where and the are populating correctly
const batchSize = 50;
for (let idx = 0; idx < fileIds.length; idx += batchSize) {
const returnedFiles = await getFileVitals(fileIds.slice(idx, idx + batchSize));
this.doWork(returnedFiles, fileRefs);
this.setState({
filesToDisplay: this.files,
title: Name,
description: Description,
});
}
}
}<script src = "https://cdnjs.cloudflare.com/ajax/libs/react/16.5.0/umd/react.production.min.js"></script>
<script src = "https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.5.0/umd/react-dom.production.min.js"></script>Вот шутливый тест, который не проходит
//DTCQ is where the data serice is implemented
jest.unmock('../../dtcq');
beforeAll(() => {
dataReaders.getFileVitals = jest.fn();
dataReaders.getFileVitals.mockReturnValue(mockData);
});
test.only('Component renders proper number of file lines if hiding single revisions.', async () => {
console.info('Running component render proper number 30');
const component = mount(<CustomizeTemplate pkg = {data.Package} files = {data.Files} hideSingleRevisions featureSet = {features} buildClicked = {jest.fn()} />);
component.setProps({ featureSet: 'p' });
component.update();
console.info('*****Expect Processed');
// Check that there are 30 file lines, as there are more if not hiding single revisions.
await expect(component.find('file-lines').children().length).toEqual(30);
});Какой для этого метод шутки? Я прочитал их асинхронные документы и не видел примеров, выполняющих такие операции.



![Безумие обратных вызовов в javascript [JS]](https://i.imgur.com/WsjO6zJb.png)


Должно быть обещание связать тесты. Лучше всего это работает с ферментом disableLifecycleMethods вариант:
const component = mount(..., { disableLifecycleMethods: true });
const props = component.props();
component.setProps({ featureSet: 'p' });
await component.instance().componentDidUpdate(props);
...
Фиксированный. Это должен быть component.instance().
Пробовал это. Прямой вызов componentDidUpdate вызывает ошибку типа, указывающую, что это не функция.