[英]Jest testing module.exports instead of export default of a class that extends
[英]How to write test with Jest for getData() using module.exports for testing but requires ESM export syntax for React/Gatsby. Json file cannot parse
以下是我的功能。 我在我的 React/Gatsby 應用程序中需要這些,因此我使用 ESM 導出語法將其導出。 但我不能用它來測試。
問題:見打印屏幕.. Jest 似乎不喜歡 Json 文件?
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
// };
在此頁面上進行以下設置可以解決問題https://www.gatsbyjs.com/docs/how-to/testing/unit-testing/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.