[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6EF7YW7270C4GAT7AZJC699":3,"skill-same:01M6EF7YW7270C4GAT7AZJC699":45},{"skillNo":4,"name":5,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":20,"frontMatter":21,"refName":22,"commitSha":23,"skillDirectory":24,"forksCount":25,"repositoryHtmlUrl":26,"repositoryHomepageUrl":27,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":29,"updatedAt":30,"install":31,"resources":44},"01M6EF7YW7270C4GAT7AZJC699","jest",null,"ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FTerminalSkills\u002Fskills\u002Fjest\u002FSKILL.md",[],[5],"2026-11-10 10:12:30",false,"# Jest — JavaScript Testing Framework\n\nJest brings a batteries-included approach to JavaScript testing. Where other frameworks require you to assemble a test runner, assertion library, and mocking tool separately, Jest ships all three in a single package. You install it, write a test, and run it. That simplicity is why it dominates the JavaScript testing landscape.\n\nThis skill walks you through Jest from first principles — writing assertions, mocking dependencies, testing asynchronous code, generating coverage reports, and integrating everything into a CI pipeline.\n\n## Installing and Configuring Jest\n\nEvery Jest setup begins with installation and a configuration file. Jest works out of the box for plain JavaScript, but most real projects need a bit of configuration for TypeScript, JSX, or module resolution.\n\n```bash\n# Install Jest and its TypeScript support\nnpm install --save-dev jest ts-jest @types\u002Fjest\n```\n\nOnce installed, create a configuration file at the root of your project. The `jest.config.ts` format gives you type checking on your configuration options.\n\n```typescript\n\u002F\u002F jest.config.ts — Root Jest configuration for a TypeScript project\nimport type { Config } from 'jest';\n\nconst config: Config = {\n  preset: 'ts-jest',\n  testEnvironment: 'node',\n  roots: ['\u003CrootDir>\u002Fsrc'],\n  testMatch: ['**\u002F__tests__\u002F**\u002F*.test.ts', '**\u002F*.spec.ts'],\n  collectCoverageFrom: [\n    'src\u002F**\u002F*.ts',\n    '!src\u002F**\u002F*.d.ts',\n    '!src\u002F**\u002Findex.ts',\n  ],\n  coverageThresholds: {\n    global: {\n      branches: 80,\n      functions: 80,\n      lines: 80,\n      statements: 80,\n    },\n  },\n  moduleNameMapper: {\n    '^@\u002F(.*)$': '\u003CrootDir>\u002Fsrc\u002F$1',\n  },\n};\n\nexport default config;\n```\n\nAdd test scripts to your `package.json` so your team has consistent commands.\n\n```json\n\u002F\u002F package.json — Scripts section for Jest commands\n{\n  \"scripts\": {\n    \"test\": \"jest\",\n    \"test:watch\": \"jest --watch\",\n    \"test:coverage\": \"jest --coverage\",\n    \"test:ci\": \"jest --ci --coverage --reporters=default --reporters=jest-junit\"\n  }\n}\n```\n\n## Writing Assertions\n\nJest's `expect` API gives you a fluent interface for asserting values. Every test follows the same pattern: arrange your data, act on it, then assert the result.\n\n```typescript\n\u002F\u002F src\u002F__tests__\u002Fmath.test.ts — Basic assertion patterns with Jest matchers\ndescribe('arithmetic operations', () => {\n  test('adds two numbers correctly', () => {\n    const result = add(2, 3);\n    expect(result).toBe(5);\n  });\n\n  test('returns an object with computed properties', () => {\n    const result = createUser('Alice', 30);\n\n    \u002F\u002F toEqual performs deep equality, unlike toBe which checks reference\n    expect(result).toEqual({\n      name: 'Alice',\n      age: 30,\n      id: expect.any(String),\n    });\n  });\n\n  test('array contains specific items', () => {\n    const fruits = getFruits();\n\n    expect(fruits).toContain('apple');\n    expect(fruits).toHaveLength(3);\n    expect(fruits).toEqual(expect.arrayContaining(['apple', 'banana']));\n  });\n\n  test('function throws on invalid input', () => {\n    expect(() => divide(10, 0)).toThrow('Cannot divide by zero');\n    expect(() => divide(10, 0)).toThrow(ArithmeticError);\n  });\n});\n```\n\n## Mock Functions and Module Mocking\n\nMocking is where Jest truly shines. You can replace any function, module, or timer with a controllable substitute. This lets you test units in complete isolation.\n\n```typescript\n\u002F\u002F src\u002F__tests__\u002FuserService.test.ts — Mocking external dependencies\nimport { UserService } from '..\u002FuserService';\nimport { database } from '..\u002Fdatabase';\n\n\u002F\u002F Replace the entire database module with auto-mocked version\njest.mock('..\u002Fdatabase');\n\nconst mockedDb = jest.mocked(database);\n\ndescribe('UserService', () => {\n  beforeEach(() => {\n    \u002F\u002F Clear all mock state between tests\n    jest.clearAllMocks();\n  });\n\n  test('fetches a user by ID from the database', async () => {\n    const mockUser = { id: '1', name: 'Alice', email: 'alice@example.com' };\n    mockedDb.findById.mockResolvedValue(mockUser);\n\n    const service = new UserService();\n    const user = await service.getUser('1');\n\n    expect(mockedDb.findById).toHaveBeenCalledWith('1');\n    expect(mockedDb.findById).toHaveBeenCalledTimes(1);\n    expect(user).toEqual(mockUser);\n  });\n\n  test('throws when user is not found', async () => {\n    mockedDb.findById.mockResolvedValue(null);\n\n    const service = new UserService();\n\n    await expect(service.getUser('999')).rejects.toThrow('User not found');\n  });\n});\n```\n\nFor more granular control, `jest.fn()` creates standalone mock functions you can pass as callbacks or method implementations.\n\n```typescript\n\u002F\u002F src\u002F__tests__\u002FeventHandler.test.ts — Using jest.fn() for callback testing\ndescribe('event handler', () => {\n  test('calls the callback with processed data', () => {\n    const callback = jest.fn();\n\n    processEvents([{ type: 'click', target: 'button' }], callback);\n\n    expect(callback).toHaveBeenCalledTimes(1);\n    expect(callback).toHaveBeenCalledWith({\n      type: 'click',\n      target: 'button',\n      timestamp: expect.any(Number),\n    });\n  });\n\n  test('mock implementation controls return value', () => {\n    const getPrice = jest.fn()\n      .mockReturnValueOnce(10.99)\n      .mockReturnValueOnce(24.99)\n      .mockReturnValue(0);\n\n    expect(getPrice()).toBe(10.99);\n    expect(getPrice()).toBe(24.99);\n    expect(getPrice()).toBe(0);\n  });\n});\n```\n\n## Testing Asynchronous Code\n\nModern JavaScript is heavily asynchronous. Jest handles promises, async\u002Fawait, and callbacks with equal ease. The key is always returning or awaiting the asynchronous operation so Jest knows when the test is done.\n\n```typescript\n\u002F\u002F src\u002F__tests__\u002Fapi.test.ts — Patterns for testing async operations\ndescribe('API client', () => {\n  test('fetches data with async\u002Fawait', async () => {\n    const data = await fetchUserProfile('alice');\n\n    expect(data.username).toBe('alice');\n    expect(data.posts).toBeInstanceOf(Array);\n  });\n\n  test('handles API errors gracefully', async () => {\n    \u002F\u002F Mock fetch to simulate a network failure\n    global.fetch = jest.fn().mockRejectedValue(new Error('Network error'));\n\n    const result = await fetchWithRetry('\u002Fapi\u002Fdata', { retries: 3 });\n\n    expect(result.error).toBe('Network error');\n    expect(global.fetch).toHaveBeenCalledTimes(4); \u002F\u002F initial + 3 retries\n  });\n\n  test('resolves multiple concurrent requests', async () => {\n    const [users, posts] = await Promise.all([\n      fetchUsers(),\n      fetchPosts(),\n    ]);\n\n    expect(users).toHaveLength(10);\n    expect(posts).toHaveLength(25);\n  });\n});\n```\n\n## Snapshot Testing\n\nSnapshots capture the output of a component or function and compare it against a saved reference. They are invaluable for catching unintended changes in UI components or serialized data structures.\n\n```typescript\n\u002F\u002F src\u002F__tests__\u002Fcomponents.test.tsx — Snapshot testing for React components\nimport { render } from '@testing-library\u002Freact';\nimport { UserCard } from '..\u002Fcomponents\u002FUserCard';\n\ndescribe('UserCard', () => {\n  test('renders correctly with user data', () => {\n    const { container } = render(\n      \u003CUserCard\n        name=\"Alice Johnson\"\n        email=\"alice@example.com\"\n        role=\"admin\"\n      \u002F>\n    );\n\n    expect(container).toMatchSnapshot();\n  });\n\n  test('inline snapshot for small outputs', () => {\n    const formatted = formatAddress({\n      street: '123 Main St',\n      city: 'Springfield',\n      state: 'IL',\n    });\n\n    expect(formatted).toMatchInlineSnapshot(`\"123 Main St, Springfield, IL\"`);\n  });\n});\n```\n\nWhen a snapshot test fails because you intentionally changed the output, update the snapshots with `jest --updateSnapshot`.\n\n## Coverage Reports and Watch Mode\n\nJest's built-in coverage tool uses Istanbul under the hood. It generates reports showing which lines, branches, functions, and statements your tests exercise.\n\n```bash\n# Generate a coverage report in multiple formats\nnpx jest --coverage --coverageReporters='text' --coverageReporters='lcov'\n```\n\nWatch mode is where Jest becomes a development companion. It watches for file changes and re-runs only the tests affected by those changes.\n\n```bash\n# Start watch mode — press 'p' to filter by filename, 't' to filter by test name\nnpx jest --watch\n```\n\nWatch mode supports interactive filtering. Press `p` to filter tests by a filename regex, `t` to filter by test name, or `a` to run all tests. This tight feedback loop makes TDD practical even in large codebases.\n\n## CI Integration\n\nIn continuous integration, Jest should run with specific flags that optimize for non-interactive environments and produce machine-readable output.\n\n```yaml\n# .github\u002Fworkflows\u002Ftest.yml — GitHub Actions workflow running Jest\nname: Tests\non: [push, pull_request]\n\njobs:\n  test:\n    runs-on: ubuntu-latest\n    steps:\n      - uses: actions\u002Fcheckout@v4\n      - uses: actions\u002Fsetup-node@v4\n        with:\n          node-version: 20\n          cache: npm\n\n      - run: npm ci\n      - run: npx jest --ci --coverage --maxWorkers=2\n\n      - uses: actions\u002Fupload-artifact@v4\n        if: always()\n        with:\n          name: coverage-report\n          path: coverage\u002Flcov-report\u002F\n```\n\nThe `--ci` flag changes snapshot behavior to fail instead of writing new snapshots, preventing accidental snapshot updates in CI. The `--maxWorkers` flag controls parallelism to match your CI runner's CPU count and avoid out-of-memory failures.\n",{},"main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002FTerminalSkills\u002Fskills\u002Fjest",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":7,"skillName":5,"commands":32,"prompt":42,"zipAvailable":43},[33,36,39],{"tool":34,"command":35},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill jest",{"tool":37,"command":38},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill jest",{"tool":40,"command":41},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill jest","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002FTerminalSkills\u002Fskills\u002Fjest\u002FSKILL.md",true,[],[46,55,64,73,79,85],{"skillNo":47,"name":48,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":49,"categories":50,"keywords":51,"publishedAt":18},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[52,53,54],"model","model hierarchy","model hierarchy skill",{"skillNo":56,"name":57,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":18},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[61,62,63],"MCP","zoom","zoom mcp",{"skillNo":65,"name":66,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":67,"categories":68,"keywords":69,"publishedAt":18},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[70,71,72,62],"sdk","zoom apps sdk","apps",{"skillNo":74,"name":75,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":18},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[75],{"skillNo":80,"name":81,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":82,"categories":83,"keywords":84,"publishedAt":18},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[81],{"skillNo":86,"name":87,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":7,"ownerLogin":8,"ownerAvatarUrl":9,"ownerAccountNo":10,"ownerDisplayName":11,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":18},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[87]]