Security News
Supply Chain Attack Detected in Solana's web3.js Library
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
vue-jest is a Jest transformer for Vue single-file components (SFCs). It allows you to use Jest to test Vue components by transforming the .vue files into a format that Jest can understand.
Transform Vue SFCs
This feature allows Jest to transform Vue single-file components (.vue files) so that they can be tested. The code sample shows how to configure Jest to use vue-jest for transforming .vue files.
module.exports = { transform: { '^.+\.vue$': 'vue-jest' } };
Mocking Vue Components
This feature allows you to mock Vue components and their dependencies during testing. The code sample demonstrates how to use vue-jest with @vue/test-utils to shallow mount a component and mock a translation function.
import { shallowMount } from '@vue/test-utils';
import MyComponent from '@/components/MyComponent.vue';
test('renders a message', () => {
const wrapper = shallowMount(MyComponent, {
mocks: {
$t: msg => msg
}
});
expect(wrapper.text()).toContain('Hello World');
});
Snapshot Testing
This feature allows you to perform snapshot testing on Vue components. The code sample shows how to use vue-jest with @vue/test-utils to create a snapshot of a component's rendered HTML and compare it to a saved snapshot.
import { shallowMount } from '@vue/test-utils';
import MyComponent from '@/components/MyComponent.vue';
test('matches snapshot', () => {
const wrapper = shallowMount(MyComponent);
expect(wrapper.html()).toMatchSnapshot();
});
vue-test-utils is the official testing utility library for Vue.js. It provides methods to mount and interact with Vue components in tests. While vue-jest focuses on transforming .vue files for Jest, vue-test-utils provides a more comprehensive set of utilities for testing Vue components.
jest-vue-preprocessor is another Jest transformer for Vue single-file components. It is similar to vue-jest in that it transforms .vue files for Jest, but it is less commonly used and lacks some of the additional features and community support that vue-jest offers.
babel-jest is a Jest transformer that uses Babel to transform JavaScript files. While it is not specific to Vue, it can be used in conjunction with other tools to transform Vue components. It is more general-purpose compared to vue-jest, which is specifically designed for Vue SFCs.
Jest Vue transformer with source map support
npm install --save-dev vue-jest
To define vue-jest as a transformer for your .vue files, you need to map .vue files to the vue-jest module.
"transform": {
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
To use source maps, you need to set mapCoverage
to true
. A full config will look like this.
{
"jest": {
"moduleFileExtensions": [
"js",
"json",
"vue"
],
"transform": {
"^.+\\.js$": "<rootDir>/node_modules/babel-jest",
".*\\.(vue)$": "<rootDir>/node_modules/vue-jest"
},
"mapCoverage": true
}
}
Example repositories testing Vue components with jest and vue-jest:
vue-jest compiles the script and template of SFCs into a JavaScript file that Jest can run. It does not currently compile the style section.
lang="ts"
, lang="typescript"
)lang="coffee"
, lang="coffeescript"
)lang="pug"
)lang="jade"
)lang="haml"
)FAQs
Jest Vue transform
The npm package vue-jest receives a total of 245,471 weekly downloads. As such, vue-jest popularity was classified as popular.
We found that vue-jest demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
A supply chain attack has been detected in versions 1.95.6 and 1.95.7 of the popular @solana/web3.js library.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.