---
id: sm-clerk-testing
name: "clerk-testing"
url: https://skills.yangsir.net/skill/sm-clerk-testing
author: clerk
domain: testing
tags: ["clerk", "unit-testing", "integration-testing", "end-to-end-testing", "authentication-testing"]
install_count: 6700
rating: 4.50 (39 reviews)
github: https://github.com/clerk/skills
---

# clerk-testing

> 掌握Clerk测试策略，利用AI技能优化Clerk相关功能的测试流程，确保系统稳定可靠，提升用户体验。

**Stats**: 6,700 installs · 4.5/5 (39 reviews)

## Before / After 对比

### 增强Clerk测试，确保系统稳定

## Readme

# clerk-testing

# Testing

## Decision Tree

Framework
Documentation

Overview
[https://clerk.com/docs/guides/development/testing/overview](https://clerk.com/docs/guides/development/testing/overview)

Playwright
[https://clerk.com/docs/guides/development/testing/playwright/overview](https://clerk.com/docs/guides/development/testing/playwright/overview)

Cypress
[https://clerk.com/docs/guides/development/testing/cypress/overview](https://clerk.com/docs/guides/development/testing/cypress/overview)

## Mental Model

Test auth = isolated session state. Each test needs fresh auth context.

- `clerkSetup()` initializes test environment

- `setupClerkTestingToken()` bypasses bot detection

- `storageState` persists auth between tests for speed

## Workflow

- Identify test framework (Playwright or Cypress)

- WebFetch the appropriate URL from decision tree above

- Follow official setup instructions

- Use `pk_test_*` and `sk_test_*` keys only

## Best Practices

- Use `setupClerkTestingToken()` before navigating to auth pages

- Use test API keys: `pk_test_xxx`, `sk_test_xxx`

- Save auth state with `storageState` for faster tests

- Use `page.waitForSelector('[data-clerk-component]')` for Clerk UI

## Anti-Patterns

Pattern
Problem
Fix

Production keys in tests
Security risk
Use `pk_test_*` keys

No `setupClerkTestingToken()`
Auth fails
Call before navigation

UI-based sign-in every test
Slow tests
Use `storageState`

## Framework-Specific

**Playwright**: Use `globalSetup` for auth state
**Cypress**: Add `addClerkCommands({ Cypress, cy })` to support file

## See Also

- [Demo Repo](https://github.com/clerk/clerk-playwright-nextjs/tree/95c7189a48c24d7e9e9744897040aa9418f68ac2/e2e)

Weekly Installs2.0KRepository[clerk/skills](https://github.com/clerk/skills)GitHub Stars27First SeenJan 30, 2026Security Audits[Gen Agent Trust HubPass](/clerk/skills/clerk-testing/security/agent-trust-hub)[SocketPass](/clerk/skills/clerk-testing/security/socket)[SnykWarn](/clerk/skills/clerk-testing/security/snyk)Installed oncodex1.8Kopencode1.8Kgithub-copilot1.8Kgemini-cli1.8Kamp1.7Kkimi-cli1.7K

---
*Source: https://skills.yangsir.net/skill/sm-clerk-testing*
*Markdown mirror: https://skills.yangsir.net/api/skill/sm-clerk-testing/markdown*