首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
社区首页 >问答首页 >如何使用module.exports为getData()编写测试,但需要使用React/Gatsby的ESM导出语法。Json文件无法解析

如何使用module.exports为getData()编写测试,但需要使用React/Gatsby的ESM导出语法。Json文件无法解析
EN

Stack Overflow用户
提问于 2021-03-28 14:42:28
回答 1查看 37关注 0票数 1

下面是我的函数。我需要在我的React/Gatsby应用程序中使用它们,因此我使用ESM导出语法将其导出。但我不能用它来测试。

问题:请参阅printscreen..Jest似乎不喜欢Json文件?

代码语言:javascript
代码运行次数:0
运行
复制
import gameOfThrones from "../data/gameOfThrones.json";

const getGameOfThronesData = ()=> {
    console.log(gameOfThrones.gameOfThrones.episodes)
}
    
const getEpisodesPerSeason = (season)=> gameOfThrones.gameOfThrones.episodes.filter(episode=> episode.season === season)
const getEpisodeData = (episodeId)=> gameOfThrones.gameOfThrones.episodes.find(episode=> episode.id === episodeId)
const getNextEpisode = episodeId => null
const getPrevEpisode = episodeId => null
    
export {getGameOfThronesData, getEpisodesPerSeason, getEpisodeData, getNextEpisode, getPrevEpisode}
    
// module.exports = {
//     getGameOfThronesData, getEpisodesPerSeason, getEpisodeData, getNextEpisode, getPrevEpisode
// };
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-03-30 04:16:18

遵循此页面上的设置即可实现https://www.gatsbyjs.com/docs/how-to/testing/unit-testing/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/66839016

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档