dimanche 28 mars 2021

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

Below are my functions. I need these in my React/Gatsby app therfor 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?enter image description here

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
// };

Aucun commentaire:

Enregistrer un commentaire