Skip to content

lijunchen/goexpect

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

goexpect

A snapshot testing library for Go that automatically updates expected values in your test source code.

Features

  • Inline Snapshots: Expected values live directly in your test code as string literals
  • Automatic Updates: Run tests with -u/-update flag or set UPDATE_EXPECT=1 environment variable to automatically update expectations
  • Zero Dependencies: Pure Go implementation with no external dependencies

Installation

go get github.com/lijunchen/goexpect

Quick Start

Inline Snapshots

Write tests with empty or placeholder expected values:

package mypackage_test

import (
    "testing"
    "github.com/lijunchen/goexpect"
)

func TestOutput(t *testing.T) {
    goexpect.Expect(t, "Hello,\nWorld!", "")  // Start with empty string
}

Run the test with the update flag to capture the snapshot:

go test -u

The library will automatically update your source code:

func TestOutput(t *testing.T) {
	goexpect.Expect(t, "Hello,\nWorld!", `Hello,
World!`) // Automatically filled in!
}

Similar Libraries in Other Languages

You may also be interested in similar snapshot testing libraries in other programming languages:

About

An inline snapshot testing library for Go

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages