Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
@testing-initializer/react
Advanced tools
Readme
This package contains all necessary utilities for bootstrapping React components in your tests.
npm i --save-dev @testing-initializer/data
or with Yarn:
yarn add -D @testing-initializer/react
First, let's create our mock database:
import { createDatabase, generateId } from "@testing-initializer/react"
interface User {
id: number
name: string
}
interface ToDo {
id: number
name: string
}
interface Project {
id: number
name: string
date: string
user: User
toDos: ToDo[]
}
interface APITypes {
user: User
toDo: ToDo
project: Project
}
const db = createDatabase<APITypes>({
user: {
id: () => generateId("user-pk"),
name: () => `User ${generateId("user-name")}`,
},
toDo: {
id: () => generateId("toDo-pk"),
name: () => `Todo ${generateId("toDo-name")}`,
},
project: {
id: () => generateId("project-pk"),
date: () => new Date().toISOString(),
name: () => `Project ${generateId("project-name")}`,
user: oneOf("user"),
toDos: manyOf("toDo"),
},
})
Now, let's say we have the following component:
interface TestComponentProps {
project: Project
}
const TestComponent = ({ project }: TestComponentProps) => {
return (
<div>
<p>{project.user.name}</p>
<p>{project.name}</p>
<div>
{project.toDos.map(({ id, name }) => (
<p key={id}>{name}</p>
))}
</div>
</div>
)
}
We can now proceed to create a renderer, a reusable function that renders your component with its necessary props:
import { createRenderer, createDatabase, generateId } from "@testing-initializer/react"
...
const renderTestComponent = createRenderer({
component: TestComponent,
data: {
currentUser: db.user.create(),
toDos: [db.toDo.create(), db.toDo.create(), db.toDo.create()],
},
props: ({ currentUser, toDos }) => ({
project: db.project.create({ toDos, user: currentUser }) as unknown as Project,
}),
renderFunction: render,
})
Notice the data
property. These extra properties are useful for getting generated data outside of the component props.
With this renderer, we can render our components consistently within tests:
it("...", () => {
const { project, currentUser, toDos } = renderTestComponent()
})
We can also render override its data
or props
:
it("...", () => {
renderTestComponent({ currentUser: db.user.create({ name: "User override" }) })
})
This project is licensed under the terms of the MIT license
FAQs
Simple Testing bootstrapping utilities for React.
The npm package @testing-initializer/react receives a total of 2 weekly downloads. As such, @testing-initializer/react popularity was classified as not popular.
We found that @testing-initializer/react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.