test-cotton-components

Write Django Cotton component tests using django-cotton-bs5 pytest fixtures.

1|Updated Apr 21, 2025
One-click install
npx skills add https://github.com/SamuelJennings/django-cotton-bs5 --skill test-cotton-components
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: test-cotton-components
Source: https://github.com/SamuelJennings/django-cotton-bs5/tree/main/.github/skills/test-cotton-components
Command: npx skills add https://github.com/SamuelJennings/django-cotton-bs5 --skill test-cotton-components

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This skill guides AI agents on how to effectively test Django Cotton components using pytest fixtures provided by django-cotton-bs5, streamlining test-writing and ensuring reliable UI component tests.

Core Features & Use Cases

  • Clear fixture usage guidance (cotton_render, cotton_render_soup, cotton_render_string, cotton_render_string_soup)
  • Testing patterns for single and multi-component scenarios
  • DOM assertions, context handling, and accessibility checks
  • Real-world examples and best practices for creating maintainable tests

Quick Start

Install and configure pytest, Django, and django-cotton-bs5 fixtures in your project, then write tests like:

  • Use cotton_render to render a single component, e.g., cotton_render('cotton_bs5.button', text='Click') and assert HTML.
  • Switch to cotton_render_soup when you need DOM traversal.
  • For inline markup, use cotton_render_string.
  • For complex structures, use cotton_render_string_soup.

Frequently Asked Questions about test-cotton-components

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I test Django Cotton components with pytest?

Testing Django Cotton components with pytest uses fixtures from django-cotton-bs5: cotton_render for HTML output, cotton_render_soup for DOM traversal, cotton_render_string for inline markup, and cotton_render_string_soup for complex structures. Write assertions against the rendered HTML to verify component behavior, context handling, and accessibility.

What fixtures are available for Cotton component testing?

django-cotton-bs5 provides four core fixtures: cotton_render returns raw HTML from a single component, cotton_render_soup parses it into a BeautifulSoup object for DOM queries, cotton_render_string renders inline Cotton markup, and cotton_render_string_soup combines inline rendering with DOM traversal for complex test scenarios.

Can I test multiple Cotton components together in pytest?

Yes. Use cotton_render_string or cotton_render_string_soup to write tests that render multiple components in a single test case, then assert DOM structure, context flow, and interactions between components using BeautifulSoup selectors and HTML assertions.

Do I need pytest and Django configured before writing Cotton component tests?

Yes. Testing Cotton components requires pytest, Django, and django-cotton-bs5 fixtures to be installed and configured in your project. Ensure your test environment can import both Django and the cotton-bs5 fixtures before writing tests.

What patterns should I follow for DOM assertions in Cotton component tests?

Use cotton_render_soup or cotton_render_string_soup to get a BeautifulSoup object, then traverse the DOM with selectors to find elements and assert their attributes, text content, and structure. Include accessibility checks and context validation in your assertions for maintainable, comprehensive tests.

How do I handle context variables when testing Cotton components?

Pass context dictionaries directly to the cotton_render fixtures as parameters when rendering components. The fixtures inject context into the component scope so you can test how components respond to different data, then assert the rendered output reflects the context correctly.