Eigen Testing Skill
Use this skill to write high-quality tests for Eigen following established patterns and best practices.
Quick Start
For Non-Relay Components
Use the template at assets/component-test-template.tsx as a starting point:
import { fireEvent, screen } from "@testing-library/react-native"
import { renderWithWrappers } from "app/utils/tests/renderWithWrappers"
For Relay Components
Use the template at assets/relay-test-template.tsx as a starting point:
import { setupTestWrapper } from "app/utils/tests/setupTestWrapper"
import { graphql } from "react-relay"
Critical Rules
- File Location: Always place tests in
__tests__directories colocated with source files - File Naming: Use
.tests.tsx(not.test.tsxor.spec.tsx) - Never Use Deprecated Utilities: Avoid
renderWithWrappersLEGACY,setupTestWrapper_LEGACY,resolveMostRecentRelayOperation,flushPromiseQueue,waitUntil,extractText,renderWithLayout - Analytics Testing: Always use
toMatchInlineSnapshot()pattern for tracking events - Async Operations: Use
findBy*queries, notwaitUntilor promise flushing
Test Structure Pattern
Follow Arrange-Act-Assert:
describe("ComponentName", () => {
it("does something specific", () => {
// Arrange: Set up and render
renderWithWrappers(<Component />)
// Act: Trigger behavior
fireEvent.press(screen.getByTestId("button-id"))
// Assert: Verify outcome
expect(mockNavigate).toHaveBeenCalledWith("/path")
})
})
Common Patterns
Testing Navigation
import { navigate } from "app/system/navigation/navigate"
expect(navigate).toHaveBeenCalledWith("/artwork/artwork-slug")
Testing Analytics
import { mockTrackEvent } from "app/utils/tests/globallyMockedStuff"
expect(mockTrackEvent).toHaveBeenCalledTimes(1)
expect(mockTrackEvent.mock.calls[0]).toMatchInlineSnapshot()
// Run test to generate snapshot, then verify it's correct
Testing Relay Data
renderWithRelay({
Me: () => ({
name: "John Doe",
artworks: {
edges: mockEdges(10), // Use mockEdges for paginated data
},
}),
})
Testing Error States
const { mockRejectLastOperation } = renderWithRelay()
mockRejectLastOperation(new Error("Network error"))
Detailed Guidelines
For comprehensive testing patterns, utilities, and examples, refer to:
- references/testing-guidelines.md - Complete testing documentation
Read this file when you need:
- Detailed examples of testing patterns
- Information about wrapper props and configuration
- Guidance on what to test and what not to test
- Mock helpers and utilities
- Additional resources and links
TestID Conventions
Use descriptive, kebab-case test IDs:
artwork-save-buttonartist-series-list-itemprice-display-container
Running Tests
yarn test # Run all tests
yarn test:watch # Watch mode
yarn test path/to/file.tests.tsx # Test specific file