Skip to content

Unit testing failure with Jest? #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
cjosh opened this issue Mar 8, 2018 · 8 comments
Open

Unit testing failure with Jest? #68

cjosh opened this issue Mar 8, 2018 · 8 comments

Comments

@cjosh
Copy link

cjosh commented Mar 8, 2018

My test suite will fail to run if I'm trying to test a component which uses vuepdf. This is with Jest on a project set up with vue-cli:

` ● Test suite failed to run

C:\frontend\uc-front\node_modules\vue-pdf\src\vuePdfNoSss.vue:1
({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){<style src="./annotationLayer.css"></style>

SyntaxError: Unexpected token <`

I don't get this error if I don't import vue-pdf in the component.

@FranckFreiburger
Copy link
Owner

...,global,jest){<style src... suggest that vuePdfNoSss.vue has not be properly processed by vue loader.
Can you give me more details about this problem ?

@cjosh
Copy link
Author

cjosh commented Mar 9, 2018

It looks like at least one other person is running into a similar error with vue-cli: vuejs/vue-cli#951. The issue might be unrelated to vue-pdf specifically, but I'm getting pretty much the same error.

@chawlaaditya8
Copy link

@cjosh did you solve your issue? I am having a similar issue on the same file.

@chawlaaditya8
Copy link

@FranckFreiburger I am facing this issue while using vue-pdf with vue-server-renderer.

@cjosh
Copy link
Author

cjosh commented Mar 13, 2018

@chawlaaditya8 I ended up switching to Karma/Mocha to get the unit tests to work.

@Kelhen
Copy link

Kelhen commented Sep 11, 2018

made it work by adding vue-pdf and vue-resize-sensor to my jest config like following

jest.config.js

transformIgnorePatterns: [
    '<rootDir>/node_modules/(?!vue-pdf/|vue-resize-sensor/)'
  ]

Then also in my my jest config I added a mocks for the worker like explained here wojtekmaj/react-pdf#67 (comment)

jest.config.js

  moduleNameMapper: {
    '^@/(.*)$': '<rootDir>/src/$1',
    '.+\\.(css|styl|less|sass|scss|png|jpg|ttf|woff|woff2)$': 'identity-obj-proxy',
    '\\.worker.js': '<rootDir>/__mocks__/workerMock.js'
  }

create the following file '__mocks__/workerMock.js' in you project and make the path above match it

workerMock.js

module.exports = Object.create(null);

@mickael-spilmont
Copy link

mickael-spilmont commented Jul 3, 2020

I have the same problem, and the solution above doesn't work for me.

EDIT :
One solution that worked for me is to add this in the /src/main.js file :

import pdf from 'vue-pdf'
Vue.component('pdf', pdf)

And remove the import and add of component vue-pdf, in this parent.

@mobsean
Copy link

mobsean commented Aug 5, 2021

Came across the exact same problem. My solution:

adding to my jest.config.js:

const esModules = ['vue-pdf', 'vue-resize-sensor'].join('|')

module.exports = {
  ....
  transformIgnorePatterns: [`<rootDir>/node_modules/(?!(${esModules}))`]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants