jest-vue-preprocessor icon indicating copy to clipboard operation
jest-vue-preprocessor copied to clipboard

Can't Handle Functional Components

Open candyapplecorn opened this issue 7 years ago • 6 comments
trafficstars

I'm submitting a ... (check one with "x")

[ x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request

Current behavior functional components error out with error ‘No script available to transform’.

Expected behavior Should not try to read a script tag from a functional component since they don't have script tags

Minimal reproduction of the problem with instructions

Try to test a functional component with jest.

What is the motivation / use case for changing the behavior? My build system won't let me push my code because these functional components are failing tests

Please tell us about your environment: node version 8.9.4 latest jest and related utils, max osx

  • jest-vue-preprocessor: 1.1.X The latest version

  • Node version : [ OSX | Linux | Windows ] 8.9.4

  • Platform: [ OSX | Linux | Windows ] osx

candyapplecorn avatar Mar 09 '18 04:03 candyapplecorn

We're having the same issue with single page components that do not have script tags.

ronald-d-rogers avatar Apr 26 '18 16:04 ronald-d-rogers

@ronald-d-rogers I faced the same problem when I was integrating tests on the project based on nuxt-community/starter-template, where AppLogo.vue does not have <script></script>.

Adding empty <script></script> was needed to avoid this error.

TakahiRoyte avatar May 30 '18 08:05 TakahiRoyte

@TakahiRoyte unfortunately, it did not help me :( When I add empty <string></string>, it receives an error:

  ● Test suite failed to run

    TypeError: Path must be a string. Received undefined

      at extractScriptContent (node_modules/jest-vue-preprocessor/index.js:34:43)
      at Object.process (node_modules/jest-vue-preprocessor/index.js:63:21)

ddosdor avatar Jun 14 '18 14:06 ddosdor

Solved by @TakahiRoyte's solution. Remember that is needed in every component, even children components.

paulmelero avatar Jul 16 '18 15:07 paulmelero

@ddosdor -- in case you haven't yet found a solution, adding export default {}; to my empty script tag fixed that error.

daltojohnso avatar Jul 18 '18 02:07 daltojohnso

Confirmed, this fixed it for me:

<script>
export default {};
</script>

Thank you @TakahiRoyte and @daltojohnso!

ewmiller avatar Aug 08 '18 19:08 ewmiller