【发布时间】:2020-02-17 18:43:50
【问题描述】:
static async getInitialProps({ query }) {
let content;
let alert;
try {
const first = query.first ? query.first : '';
content = await getContent(first);
} catch (error) {
alert = 'There was an error loading data, please try again.';
content = [];
}
return {
content,
alert,
};
}
我正在尝试为此逻辑编写测试,但因为它是服务器端代码,我很难理解我如何为它编写测试,因为它在 instance() 中对我不可用。
Google 没有向我展示这个方法,所以我想知道其他人是如何处理为 getInitial 道具编写测试的。
【问题讨论】:
标签: javascript reactjs jestjs next.js