1 个不稳定版本
0.0.2 | 2022年4月11日 |
---|---|
0.0.1 |
|
#9 在 #jest
12KB
375 代码行
expect-rust
这是类似于 jest expect
的匹配器。
示例
expect
当您想测试一个值时使用的函数。测试总是从这里开始。
let a = some_function();
expect(&a).equals(&expected);
equals
评估等价性
let a = some_function();
expect(&a).equals(&expected);
应该恐慌
期望函数调用在 Panic 时终止
let f = || {
panic!("err");
};
expect(&f).should_panic(); // Ok
let f = || {
// non panic
};
expect(&f).should_panic(); // Ng
is some and equals
测试其中一个值可以获取,并且可以获取预期值。
let v = Some(100);
expect(&v).is_some_equal_to(&100);
用法
使用 crates.io 仓库;将其添加到您的 Cargo.toml 中,与其他依赖项一起
[dependencies]
expect_rs = "*"
或
expect_rs = { git = "https://github.com/ishibashi-futos/expect-rust", branch = "main" }
许可证
MIT
依赖项
~2–3MB
~53K SLoC