如何在elixir中正确断言struct类型

时间:2018-04-19 14:10:18

标签: testing elixir assert

我知道你可以断言这样的类型结构(虽然它更像是一个模块断言):

assert foo.__struct__ == Foo

但有更优雅的方式吗?类似的东西:

assert type(foo) == %Foo{}

1 个答案:

答案 0 :(得分:11)

您可以使用=和模式匹配:

assert %Foo{} = foo
相关问题