New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@cs-magic/jest-config

Package Overview
Dependencies
Maintainers
0
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cs-magic/jest-config

Shared Jest configurations for CS Magic projects

latest
npmnpm
Version
0.2.0
Version published
Weekly downloads
1
-50%
Maintainers
0
Weekly downloads
 
Created
Source

@cs-magic/jest-config

CS Magic 项目的共享 Jest 配置。

安装

npm install --save-dev @cs-magic/jest-config

使用

基础配置

// jest.config.js
module.exports = require('@cs-magic/jest-config')

React 项目

// jest.config.js
module.exports = require('@cs-magic/jest-config/presets/react')

Next.js 项目

// jest.config.js
module.exports = require('@cs-magic/jest-config/presets/next')

自定义配置

// jest.config.js
const baseConfig = require('@cs-magic/jest-config/presets/react')

module.exports = {
  ...baseConfig,
  // 你的自定义配置
  testTimeout: 10000,
  coverageThreshold: {
    global: {
      branches: 80,
      functions: 80,
      lines: 80,
      statements: 80,
    },
  },
}

特性

  • TypeScript 支持
  • React Testing Library 集成
  • 用户事件模拟
  • 文件模块模拟
  • 自定义匹配器
  • 代码覆盖率报告

测试示例

import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { MyComponent } from './MyComponent'

describe('MyComponent', () => {
  it('renders correctly', () => {
    render(<MyComponent />)
    expect(screen.getByRole('button')).toBeInTheDocument()
  })
})

命令

package.json 中添加:

{
  "scripts": {
    "test": "jest",
    "test:watch": "jest --watch",
    "test:coverage": "jest --coverage"
  }
}

常见问题

1. 测试超时

修改超时时间:

module.exports = {
  ...require('@cs-magic/jest-config'),
  testTimeout: 10000,
}

2. 模拟模块

jest.mock('./myModule', () => ({
  myFunction: jest.fn(),
}))

3. 自定义转换器

module.exports = {
  ...require('@cs-magic/jest-config'),
  transform: {
    '^.+\\.mdx?$': '@mdx-js/jest-transformer',
  },
}

Keywords

jest

FAQs

Package last updated on 13 Nov 2024

Did you know?

Socket

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.

Install

Related posts