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

Running jest : flatpickr is not a function #30

Closed
bartektelec opened this issue Jul 5, 2021 · 2 comments
Closed

Running jest : flatpickr is not a function #30

bartektelec opened this issue Jul 5, 2021 · 2 comments
Labels
invalid tooling upstream Not actually an issue with this package

Comments

@bartektelec
Copy link

I've tried running tests on components that include this package but they end up failing.
At first I would get
TypeError: Flatpickr is not a constructor
then I added 'jest-svelte-resolver' to my jest.config.js which gave me
SyntaxError: Unexpected token '<'

So I added transformIgnorePatterns: ['node_modules/(?!svelte-flatpickr)/'], in the jest.config
and this is where I am stuck. I keep getting
TypeError: flatpickr is not a function

I've previously tried doing import * as Flatpickr from 'svelte-flatpickr';, that would bypass the test problems, but break the app.

jest.config.js

const { pathsToModuleNameMapper } = require('ts-jest/utils');
const { compilerOptions } = require('./tsconfig');

module.exports = {
  preset: 'ts-jest',
  resolver: 'jest-svelte-resolver',
  testEnvironment: 'node',
  transform: {
    '^.+\\.svelte$': [
      'svelte-jester',
      {
        preprocess: true
      }
    ],
    '^.+\\.ts$': 'ts-jest'
  },
  transformIgnorePatterns: ['node_modules/(?!svelte-flatpickr)/'],
  setupFilesAfterEnv: [
    '@testing-library/jest-dom/extend-expect',
    './setupTests.ts'
  ],
  moduleFileExtensions: ['js', 'ts', 'svelte'],
  modulePathIgnorePatterns: ['<rootDir>/cypress/'],
  moduleNameMapper: pathsToModuleNameMapper(compilerOptions.paths, {
    prefix: '<rootDir>'
  })
};

Has anyone been able to fix this issue?

@jacobmischka
Copy link
Owner

Do you have a repo or setup with jest I can look at? I use jest for unit tests but not often for component testing.

@jacobmischka
Copy link
Owner

Nevermind, I was able to get to the same point you were: https://github.com/jacobmischka/svelte-typescript-jest/tree/svelte-flatpickr-test

I think this is fundamentally an issue with svelte-jester (svelteness/svelte-jester#16). Even when taking svelte-flatpickr out of the loop entirely and trying to just import flatpickr from 'flatpickr' also failed, despite having "allowSyntheticDefaultImports": true in tsconfig.json.

@jacobmischka jacobmischka added invalid upstream Not actually an issue with this package labels Oct 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
invalid tooling upstream Not actually an issue with this package
Projects
None yet
Development

No branches or pull requests

2 participants