Below are my functions. I need these in my React/Gatsby app therefore I export it with ESM export syntax. but I cannot use it for testing.
problem to: see printscreen.. Jest doesn't seem to like the Json file?
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
// };
Following setup on this page does the trick https://www.gatsbyjs.com/docs/how-to/testing/unit-testing/