#expect #jest #matcher #equals #panic

expect_rs

这是类似于 jest expect 的匹配器

1 个不稳定版本

0.0.2 2022年4月11日
0.0.1 2022年4月11日

#9#jest

MIT 许可证

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