- Rust 96.3%
- TypeScript 3.5%
- Makefile 0.1%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
|
Some checks failed
Tests / Test on Latest (push) Has been cancelled
Tests / Test on Latest-1 (push) Has been cancelled
Tests / Test on Latest-2 (push) Has been cancelled
Tests / Run the in-tree version of cargo-insta on ourselves (push) Has been cancelled
Tests / Check on MSRV (push) Has been cancelled
Tests / Test latest deps (push) Has been cancelled
Tests / Build docs (push) Has been cancelled
Tests / clippy (push) Has been cancelled
Tests / Test with minimal version resolution (push) Has been cancelled
Tests / rustfmt (push) Has been cancelled
|
||
| .github | ||
| .vscode | ||
| assets | ||
| cargo-insta | ||
| insta | ||
| scripts | ||
| vscode-insta | ||
| .gitignore | ||
| .pre-commit-config.yaml | ||
| .typos.toml | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CHANGELOG.md | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| Makefile | ||
| README.md | ||
insta: a snapshot testing library for Rust
Introduction
Snapshots tests (also sometimes called approval tests) are tests that
assert values against a reference value (the snapshot). This is similar
to how assert_eq! lets you compare a value against a reference value but
unlike simple string assertions, snapshot tests let you test against complex
values and come with comprehensive tools to review changes.
Snapshot tests are particularly useful if your reference values are very large or change often.
Example
#[test]
fn test_hello_world() {
insta::assert_debug_snapshot!(vec![1, 2, 3]);
}
Curious? There is a screencast that shows the entire workflow: watch the insta introduction screencast. Or if you're not into videos, read the 5 minute introduction.
Insta also supports inline snapshots which are stored right in your source file instead of separate files. This is accomplished by the companion cargo-insta tool.
Editor Support
For looking at .snap files there is a vscode extension
which can syntax highlight snapshot files, review snapshots and more. It can be installed from the
marketplace: view on marketplace.
Diffing
Insta uses similar for all its diffing
operations. You can use it independently of insta. You can use the
similar-asserts crate to get
inline diffs for the standard assert_eq! macro to achieve insta like diffs
for regular comparisons:
use similar_asserts::assert_eq;
fn main() {
let reference = vec![1, 2, 3, 4];
assert_eq!(reference, (0..4).collect::<Vec<_>>());
}
Sponsor
If you like the project and find it useful you can become a sponsor.
