jechav/tiny-slider-react

Making tests fail

nayrl opened this issue · 3 comments

nayrl commented
  1. Installed create-react-app out of the box ran npm test, all tests pass.
  2. Installed tiny-slider-react, ran npm test, all tests fail with the following errors.

`
FAIL src/App.test.js
● Test suite failed to run

Jest encountered an unexpected token

This usually means that you are trying to import a file which Jest cannot parse, e.g. it's not plain JavaScript.

By default, if Jest sees a Babel config, it will use that to transform your files, ignoring "node_modules".

Here's what you can do:
 • To have some of your "node_modules" files transformed, you can specify a custom "transformIgnorePatterns" in your config.
 • If you need a custom transformation specify a "transform" option in your config.
 • If you simply want to mock your non-JS modules (e.g. binary assets) you can stub them out with the "moduleNameMapper" config option.

You'll find more details and examples of these config options in the docs:
https://jestjs.io/docs/en/configuration.html

Details:

/my-app/node_modules/ventura-slider/src/tiny-slider.module.js:5
import './helpers/keys';
^^^^^^

SyntaxError: Unexpected token import

  at ScriptTransformer._transformAndBuildScript (node_modules/@jest/transform/build/ScriptTransformer.js:471:17)
  at ScriptTransformer.transform (node_modules/@jest/transform/build/ScriptTransformer.js:513:25)
  at Object.<anonymous> (node_modules/tiny-slider-react/build/Carousel.js:19:19)

Test Suites: 1 failed, 1 total
Tests: 0 total
Snapshots: 0 total
Time: 0.473s
Ran all test suites.

Watch Usage: Press w to show more.
`

@liannary hi i just update the library, i manage to solve this by recompiling the original source code.

nayrl commented

Hi, this is still not resolved. Following the same steps as above, the error trace is as follows when trying to run tests

 FAIL  src/App.test.js
  ✕ renders without crashing (71ms)

  ● renders without crashing

    TypeError: Cannot read property 'appendChild' of null

       5 | it('renders without crashing', () => {
       6 |   const div = document.createElement('div');
    >  7 |   ReactDOM.render(<App />, div);
         |            ^
       8 |   ReactDOM.unmountComponentAtNode(div);
       9 | });
      10 | 

      at getClientWidth (node_modules/ventura-slider/dist/tiny-slider.parsed.js:605:8)
      at getClientWidth (node_modules/ventura-slider/dist/tiny-slider.parsed.js:608:21)
      at getViewportWidth (node_modules/ventura-slider/dist/tiny-slider.parsed.js:612:12)
      at tns (node_modules/ventura-slider/dist/tiny-slider.parsed.js:330:18)
      at Carousel.build (node_modules/tiny-slider-react/build/Carousel.js:123:44)
      at Carousel.componentDidMount (node_modules/tiny-slider-react/build/Carousel.js:199:12)
      at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:17334:22)
      at commitAllLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:18736:7)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:149:14)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:199:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:256:31)
      at commitRoot (node_modules/react-dom/cjs/react-dom.development.js:18948:7)
      at node_modules/react-dom/cjs/react-dom.development.js:20418:5
      at Object.unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:255:12)
      at completeRoot (node_modules/react-dom/cjs/react-dom.development.js:20417:13)
      at performWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:20346:9)
      at performWork (node_modules/react-dom/cjs/react-dom.development.js:20254:7)
      at performSyncWork (node_modules/react-dom/cjs/react-dom.development.js:20228:3)
      at requestWork (node_modules/react-dom/cjs/react-dom.development.js:20097:5)
      at scheduleWork (node_modules/react-dom/cjs/react-dom.development.js:19911:5)
      at scheduleRootUpdate (node_modules/react-dom/cjs/react-dom.development.js:20572:3)
      at updateContainerAtExpirationTime (node_modules/react-dom/cjs/react-dom.development.js:20600:10)
      at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:20657:10)
      at ReactRoot.Object.<anonymous>.ReactRoot.render (node_modules/react-dom/cjs/react-dom.development.js:20953:3)
      at node_modules/react-dom/cjs/react-dom.development.js:21090:14
      at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:20459:10)
      at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:21086:5)
      at Object.render (node_modules/react-dom/cjs/react-dom.development.js:21155:12)
      at Object.render (src/App.test.js:7:12)

  console.error node_modules/jsdom/lib/jsdom/virtual-console.js:29
    Error: Uncaught [TypeError: Cannot read property 'appendChild' of null]
        at reportException (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
        at invokeEventListeners (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:209:9)
        at HTMLUnknownElementImpl._dispatch (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
        at HTMLUnknownElementImpl.dispatchEvent (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
        at HTMLUnknownElementImpl.dispatchEvent (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
        at HTMLUnknownElement.dispatchEvent (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
        at Object.invokeGuardedCallbackDev (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:199:16)
        at invokeGuardedCallback (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:256:31)
        at commitRoot (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:18948:7)
        at /Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20418:5 TypeError: Cannot read property 'appendChild' of null
        at getClientWidth (/Users/liannastrata3/Desktop/test/node_modules/ventura-slider/dist/tiny-slider.parsed.js:605:8)
        at getClientWidth (/Users/liannastrata3/Desktop/test/node_modules/ventura-slider/dist/tiny-slider.parsed.js:608:21)
        at getViewportWidth (/Users/liannastrata3/Desktop/test/node_modules/ventura-slider/dist/tiny-slider.parsed.js:612:12)
        at tns (/Users/liannastrata3/Desktop/test/node_modules/ventura-slider/dist/tiny-slider.parsed.js:330:18)
        at Carousel.build (/Users/liannastrata3/Desktop/test/node_modules/tiny-slider-react/build/Carousel.js:123:44)
        at Carousel.componentDidMount (/Users/liannastrata3/Desktop/test/node_modules/tiny-slider-react/build/Carousel.js:199:12)
        at commitLifeCycles (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:17334:22)
        at commitAllLifeCycles (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:18736:7)
        at HTMLUnknownElement.callCallback (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:149:14)
        at invokeEventListeners (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:193:27)
        at HTMLUnknownElementImpl._dispatch (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:119:9)
        at HTMLUnknownElementImpl.dispatchEvent (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:82:17)
        at HTMLUnknownElementImpl.dispatchEvent (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/nodes/HTMLElement-impl.js:30:27)
        at HTMLUnknownElement.dispatchEvent (/Users/liannastrata3/Desktop/test/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:157:21)
        at Object.invokeGuardedCallbackDev (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:199:16)
        at invokeGuardedCallback (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:256:31)
        at commitRoot (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:18948:7)
        at /Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20418:5
        at Object.unstable_runWithPriority (/Users/liannastrata3/Desktop/test/node_modules/scheduler/cjs/scheduler.development.js:255:12)
        at completeRoot (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20417:13)
        at performWorkOnRoot (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20346:9)
        at performWork (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20254:7)
        at performSyncWork (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20228:3)
        at requestWork (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20097:5)
        at scheduleWork (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:19911:5)
        at scheduleRootUpdate (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20572:3)
        at updateContainerAtExpirationTime (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20600:10)
        at updateContainer (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20657:10)
        at ReactRoot.Object.<anonymous>.ReactRoot.render (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20953:3)
        at /Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:21090:14
        at unbatchedUpdates (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:20459:10)
        at legacyRenderSubtreeIntoContainer (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:21086:5)
        at Object.render (/Users/liannastrata3/Desktop/test/node_modules/react-dom/cjs/react-dom.development.js:21155:12)
        at Object.render (/Users/liannastrata3/Desktop/test/src/App.test.js:7:12)
        at Object.asyncJestTest (/Users/liannastrata3/Desktop/test/node_modules/jest-jasmine2/build/jasmineAsyncInstall.js:102:37)
        at resolve (/Users/liannastrata3/Desktop/test/node_modules/jest-jasmine2/build/queueRunner.js:43:12)
        at new Promise (<anonymous>)
        at mapper (/Users/liannastrata3/Desktop/test/node_modules/jest-jasmine2/build/queueRunner.js:26:19)
        at promise.then (/Users/liannastrata3/Desktop/test/node_modules/jest-jasmine2/build/queueRunner.js:73:41)
        at <anonymous>
        at process._tickCallback (internal/process/next_tick.js:189:7)

  console.error node_modules/react-dom/cjs/react-dom.development.js:17117
    The above error occurred in the <Carousel> component:
        in Carousel (at App.js:6)
        in App (at App.test.js:7)
    
    Consider adding an error boundary to your tree to customize error handling behavior.
    Visit https://fb.me/react-error-boundaries to learn more about error boundaries.

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        1.545s, estimated 2s
Ran all test suites related to changed files.

hi,
I've got the same Problem.
+1