Categories
Development

Importing local files in `jest.config.js` file

In my jest.config.js file, I need to populate globals property. For populating the globals property I need to require local modules, as shown below: const path = require(‘path’) const server = require(‘./server/cfg’) module.exports = { rootDir: path.resolve(__dirname), moduleFileExtensions: [ ‘js’, ‘json’, ‘vue’, ‘ts’ ], moduleNameMapper: { ‘^@/(.*)$’: ‘<rootDir>/src/$1’ }, transform: { “.*\\.(vue)$”: “<rootDir>/node_modules/vue-jest”, “^.+\\.(js|jsx)?$”: “<rootDir>/node_modules/babel-jest”, […]

Categories
Development Vue

Error Cannot tween a null target in Unit test with GSAP-TweenMax, Jest and VueJs

I have an error when trying to perform a unit test with Jest on a component in VueJs that has an animation made with TweenMax GSAP. The error is: Cannot tween a null target. in ztButton.spec.js jest.mock(‘gsap/TweenMax’) it(‘Component must to emit event on click’, () => { const wrapper = shallowMount(ztButton) const spy = sinon.spy() […]

Categories
Development

ts-jest: map ‘@’ char to /src folder

I have a node project with typescript, and I have the following paths configured in my tsconfig.json file: “paths”: { /* A series of entries which re-map imports to lookup locations relative to the ‘baseUrl’. */ “@project/*”: [“./../*”], “@*”: [“./*”], }, My config files are at /project folder, and my sources at /project/src It works […]

Categories
Development Vue

How to configure Jest added to an app via Vue cli 3?

I’m trying to introduce testing with Jest into an app build with Vue. I’ve run vue add unit-jest and similarly to what testing single file components with Jest guide suggests, created the following simple test file (Paginator.spec.js in the same folder as Paginator.vue, that is /src/components): import { mount } from ‘@vue/test-utils’ import Paginator from […]