vitest-gen
v0.1.4
Published
Package for generating NextJS template files with corresponding Vitest test files
Downloads
100
Maintainers
Readme
Features
- Generate both component (.tsx) and function (.ts) template files
- Generate template unit tests matching the directory structure of create files
vitest-gen requires Vitest >=2.1.1 Node >=v20.0.0
Examples
Generate component
$ npx vitest-gen app/home/page.tsx HomePage
// app/home/page.tsx
export const HomePage = () => {
return (
<div>
<h1>HomePage</h1>
</div>
)
}
// __test__/app/home/page.test.tsx
import { expect, test } from 'vitest'
import { render, screen } from '@testing-library/react'
import { HomePage } from '@/app/home/page'
test('HomePage', () => {
render(<HomePage />)
expect(screen.getByRole('heading', { level: 1, name: 'HomePage' })).toBeDefined()
})
Generate function
$ npx vitest-gen lib/testFunc.ts TestFunc
// lib/testFunc.ts
export function TestFunc() {
return 0
}
// __test__/lib/testFunc.test.ts
import { expect, test } from 'vitest'
import { TestFunc } from '@/lib/testFunc'
test('TestFunc', () => {
expect(TestFunc()).equal(0, "TestFunc should return 0")
})
License
MIT License © 2024-Present Kristian Kolehmainen