Skip to content
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

ReferenceError: jQuery is not defined while running a jest unit test cases. #128

Open
amolht opened this issue May 23, 2023 · 1 comment

Comments

@amolht
Copy link

amolht commented May 23, 2023

Hi team, i am using lform in my app but when running a jest unit test cases I am getting the following error from Scipts

Test suite failed to run

ReferenceError: jQuery is not defined



  at K (src/assets/lforms-33.3.3/webcomponent/main.js:15094:28)
  at Object.5076 (src/assets/lforms-33.3.3/webcomponent/main.js:15091:90)
  at a (src/assets/lforms-33.3.3/webcomponent/runtime.js:5:90)
  at Object.7944 (src/assets/lforms-33.3.3/webcomponent/main.js:9899:22)
  at a (src/assets/lforms-33.3.3/webcomponent/runtime.js:5:90)
  at src/assets/lforms-33.3.3/webcomponent/main.js:16751:21
  at n (src/assets/lforms-33.3.3/webcomponent/runtime.js:24:21)
  at Object.<anonymous> (src/assets/lforms-33.3.3/webcomponent/main.js:5:59) 

here is my jest config file

 /* eslint-disable */
export default {
  displayName: 'sapphire-components-risk-assessment-form',
  preset: '../../../jest.preset.js',
  setupFilesAfterEnv: ['<rootDir>/src/jquery.setup.ts'],
  coverageDirectory: '../../../coverage/libs/sapphire-components/risk-assessment-form',
  moduleNameMapper: {
    'jquery': '<rootDir>/src/assets/jquery.min.js',
  },
  setupFiles: [
    //'<rootDir>/src/assets/jquery.min.js',
    '<rootDir>/src/assets/lforms-33.3.3/webcomponent/assets/lib/zone.min.js',
    '<rootDir>/src/assets/lforms-33.3.3/webcomponent/runtime.js',
    '<rootDir>/src/assets/lforms-33.3.3/webcomponent/polyfills.js',
    '<rootDir>/src/assets/lforms-33.3.3/webcomponent/scripts.js',
    '<rootDir>/src/assets/lforms-33.3.3/webcomponent/main.js',
    '<rootDir>/src/assets/lforms-33.3.3/fhir/R4/lformsFHIR.min.js',
  ],

  transform: {
    '^.+\\.(ts|mjs|js|html)$': [
      'jest-preset-angular',
      {
        tsconfig: '<rootDir>/tsconfig.spec.json',
        stringifyContentPathRegex: '\\.(html|svg)$',
      },
    ],
  },
  transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'],
  snapshotSerializers: [
    'jest-preset-angular/build/serializers/no-ng-attributes',
    'jest-preset-angular/build/serializers/ng-snapshot',
    'jest-preset-angular/build/serializers/html-comment',
  ],
};

@plynchnlm
Copy link
Member

lforms' jQuery dependency is included with the scripts.js file. If that is loaded in the page ahead of main.js, it should have what it needs. I don't know a lot about jest configuration, but I see you have jquery listed in "moduleNameMapper", which might confuse things. Maybe try commenting that out?

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

No branches or pull requests

2 participants