Skip to content

Commit

Permalink
Update README with import alias support and another limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
KasonBraley committed Jul 6, 2024
1 parent 30c1eda commit ae8d953
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ Limitations:
- When updating a snapshot that uses the `<snap:ignore>` marker, the marker is overwritten. This can be
worked around by undoing that specific line back to the ignore marker(I do this easily with Git hunks),
but it is indeed a little annoying to deal with.
- Updating the snapshot does not currently work if the `snap.Snap` function is assigned to a different variable.
Such as `check := snap.Snap`.

Inspired by:

Expand Down Expand Up @@ -101,6 +103,27 @@ func TestSnapJSONWithIgnore(t *testing.T) {
}
```

#### Import alias

Snapshot updating still works if you decide to import this package under a different alias, such as:

```go
import (
"strconv"
"testing"
foo "github.com/KasonBraley/snap"
)

func TestExample(t *testing.T) {
checkAddition := func(x int, y int, want *snap.Snapshot) {
got := x + y
want.Diff(strconv.Itoa(got))
}

checkAddition(2, 2, foo.Snap(t, "8")) // "foo" instead of "snap" still works when using SNAP_UPDATE=1
}
```

### Examples

The [./examples](./examples) directory showcases some more elaborate use cases for this package, such
Expand Down

0 comments on commit ae8d953

Please sign in to comment.