DEV Community

Discussion on: Testable code with VueJS and TypeScript

Collapse
 
slushnys profile image
Zigmas Slušnys • Edited

I've been trying to play around with this and came to a stop when trying to import any exported module from firebase plugin in the directory of '@/plugins/firebase.js', so e.g. import { db, storage } from '@/plugins/firebase'
doesn't work throwing error to me

Cannot find module '@/plugins/firebase' from 'dealsStore.ts'

    However, Jest was able to find:
        '../dealsStore.ts'

I tried workarounds in jest etc, but wasn't able to proceed. Have you ever encountered this before?

EDIT:

Found a way to fix it. Jest did not have the aliases for module importing therefore @ alias did not resolve to correct file paths. What you can do is include the configuration in jest.config.js depending on which alias you use:

moduleNameMapper: {
    "^~/(.*)$": "<rootDir>/$1",
    "^~~/(.*)$": "<rootDir>/$1",
    "^@/(.*)$": "<rootDir>/$1"
  },