0.1.4 • Published 10 months ago

vitest-gen v0.1.4

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

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

0.1.4

10 months ago

0.1.3

10 months ago

0.1.2

10 months ago

0.1.1

10 months ago

0.1.0

10 months ago