testing

typescript
import { render, screen } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import { PostCard } from '../PostCard'
import { Post } from '@/types'

const mockPost: Post = {

React Testing Library for component tests

react testing testing-library
by Maya Patel 2 tabs
typescript
import { defineConfig, devices } from '@playwright/test';
import path from 'node:path';

export const authFile = path.join(__dirname, '.auth/user.json');

export default defineConfig({

Playwright smoke test for auth flow

testing playwright e2e
by codesnips 4 tabs
ruby
class CommentsController < ApplicationController
  before_action :set_post

  def create
    @comment = @post.comments.build(comment_params)

Request spec: Turbo Stream template is rendered

rails hotwire turbo
by codesnips 3 tabs
yaml
name: CI

on:
  push:
    branches: [main]
  pull_request:

GitHub Actions: cache + tests + build

ci github-actions node
by codesnips 3 tabs
ruby
require 'rails_helper'

RSpec.describe User, type: :model do
  subject(:user) { build(:user) }

  describe 'validations' do

Advanced RSpec testing with shared examples

ruby rspec testing
by Sarah Mitchell 3 tabs
ruby
# spec/factories/users.rb
FactoryBot.define do
  factory :user do
    sequence(:email) { |n| "user#{n}@example.com" }
    name { Faker::Name.name }
    password { 'password123' }

Factory Bot for flexible test data generation

ruby rspec factory-bot
by Sarah Mitchell 1 tab
rust
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Interval {
    pub start: i64,
    pub end: i64,
}

Merging Overlapping Booking Intervals with a Sweep-Line in Rust

rust algorithms intervals
by codesnips 3 tabs
swift
import XCTest
import Combine
@testable import MyApp

class PostsViewModelTests: XCTestCase {
    var viewModel: PostsViewModel!

Unit testing with XCTest and mocks

swift testing xctest
by Sofia Martinez 2 tabs
java
package com.example.demo.service;

import com.example.demo.exception.ResourceNotFoundException;
import com.example.demo.model.User;
import com.example.demo.repository.UserRepository;
import org.junit.jupiter.api.BeforeEach;

JUnit 5 and Mockito testing strategies

java testing junit
by David Kumar 2 tabs
ruby
# Gemfile
gem 'view_component'

# app/components/button_component.rb
class ButtonComponent < ViewComponent::Base
  VARIANTS = %w[primary secondary danger].freeze

ViewComponent for reusable, testable view components

ruby rails view-component
by Sarah Mitchell 2 tabs
python
import factory
from factory.django import DjangoModelFactory
from factory import Faker, SubFactory, post_generation
from blog.models import Post, Comment, Tag
from django.contrib.auth import get_user_model

Django test fixtures with factory_boy

django python testing
by Priya Sharma 1 tab
php
<?php

namespace Tests\Feature;

use App\Models\Post;
use App\Models\User;

Laravel test writing with PHPUnit

laravel testing phpunit
by Carlos Mendez 2 tabs