dimanche 18 avril 2021

Mocha cannot find module

I am trying to write simple Unit Test with Mocha & Chai in my React Client ( I am using typescript in my react client).

Unfortunately I am not able to start the test, because my module can not be found (App.tsx). My path is correct, 100%. I am using Typescript, so that it is an App.tsx file instead of App.js . My assumption is that typescript is blocking something. But I do not know what.

SyntaxError: Cannot use import statement outside a module

babel.config.js

module.exports = (api) => {
  const presets = ['react-app']
  const plugins = [
    '@babel/plugin-transform-modules-commonjs',
    'inline-react-svg',
  ]

  api.cache(false)

  return {
    presets,
    plugins,
  }
}

package.json

 "test": "NODE_ENV=test mocha  --require @babel/register --require       ignore-styles src/test/*.test.js",

App.test.js

import React from 'react'
import { configure, shallow } from 'enzyme'
import chai, { expect } from 'chai'
import chaiEnzyme from 'chai-enzyme'
import Adapter from 'enzyme-adapter-react-16'
import App from '../App.tsx'
configure({
  adapter: new Adapter(),
})
describe('Testin <App/> Component', () => {
  it('App renders a message', () => {
    const wrapper = shallow(<App />)
    const message = (
      <p>
        Edit <code>src/App.tsx</code> and save to reload.
      </p>
    )
    expect(wrapper).to.contain(message)
  })
  chai.use(chaiEnzyme())
})

Aucun commentaire:

Enregistrer un commentaire