Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@vtex/test-tools
Advanced tools
Tools for testing JavaScript, TypeScript, Node and React applications
$ yarn add @vtex/test-tools @babel/runtime -D
Add a new script to your package.json
:
"test": "vtex-test-tools test"
Run in your terminal:
$ yarn test
Under the hood, we use Jest, so you can pass Jest flags as parameters: read the docs.
react
moduleThe module react
makes it easy to test VTEX IO React apps.
import React from 'react'
import { render } from '@vtex/test-tools/react'
import HelloWorld from './HelloWorld'
test('should render the Hello!', () => {
const { getByText } = render(<HelloWorld />)
const element = getByText(/Hello!/)
expect(element).toBeDefined()
})
This module uses react-testing-library
under the hood, so most of its API it's the same: read the docs.
There are few new features added to it:
We will automatically wrap your component with an IntlProvider
with your app's messages/en-US.json
messages.
You can change the default locale being used adding a config to your package.json
. Example:
"vtexTestTools": {
"defaultLocale": "pt-BR"
}
If you want to change the locale just in a test, you may pass the locale
option. Example:
import React from 'react'
import { render } from '@vtex/test-tools/react'
import HelloWorld from './HelloWorld'
test('should render the example translated to portuguese', () => {
const { getByText } = render(
<HelloWorld />,
{ locale: 'pt' }
)
const element = getByText(/Olá!/)
expect(element).toBeDefined()
})
We automatically wrap your component with an Apollo's MockProvider
.
You can pass props to it using the graphql
option. Example:
import React from 'react'
import { render } from '@vtex/test-tools/react'
import GraphqlComponent from './GraphqlComponent'
import GET_BOOKS from './getBooks.graphql'
test('should render mock graphql responses', async () => {
const bookMock = {
request: {
query: GET_BOOKS,
},
result: {
data: {
books: [
{
id: 10,
title: 'Hello',
}
]
}
}
}
const { getByText } = render(<GraphqlComponent />, {
graphql: { mocks: [bookMock] }
})
expect(getByText(/Loading/)).toBeDefined()
await new Promise(resolve => setTimeout(resolve, 0))
expect(getByText(/Hello/)).toBeDefined()
})
These are some common use cases that might be helpful to see how it's done:
MIT © VTEX
[0.1.1] - 2019-03-12
FAQs
VTEX IO testing tools
The npm package @vtex/test-tools receives a total of 7,858 weekly downloads. As such, @vtex/test-tools popularity was classified as popular.
We found that @vtex/test-tools demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.