I got a few csv files I am rendering as tables in a react app. I want to write tests for the table component but jest fails with
Jest encountered an unexpected token
Jest failed to parse a file. This happens e.g. when your code or its dependencies use non-standard JavaScript syntax, or when Jest is not configured to support such syntax
I did some reading and I from what I gathered, jest needs to be told how to handle special files and one way to do that is with transformers. I tried to write one myself but not sure if I'm doing it right because everything I tried just doesn't seem to make the test file run successfully.
here is my jest.config:
module.exports = {
moduleNameMapper: {
'^.*\\.scss$': 'identity-obj-proxy',
'^.+\\.svg$': 'jest-svg-transformer',
'^d3$': '<rootDir>/node_modules/d3/dist/d3.min.js',
'd3-zoom': '<rootDir>/node_modules/d3-zoom/dist/d3-zoom.min.js',
'd3-dispatch': '<rootDir>/node_modules/d3-dispatch/dist/d3-dispatch.min.js',
'd3-drag': '<rootDir>/node_modules/d3-drag/dist/d3-drag.min.js',
'd3-selection':
'<rootDir>/node_modules/d3-selection/dist/d3-selection.min.js',
'd3-transition':
'<rootDir>/node_modules/d3-transition/dist/d3-transition.min.js',
'd3-timer': '<rootDir>/node_modules/d3-timer/dist/d3-timer.min.js',
'd3-ease': '<rootDir>/node_modules/d3-ease/dist/d3-ease.min.js',
},
testEnvironment: 'jsdom',
};
Thanks for your help!