Verifying struct keys presence in tests

422 views Asked by At
assert Contract.fetch(contract: valid_address) == %Contract{
         contract: "0x3D29Aa78fB558F84112bbC48a84F371147A920C9",
         name: "bla",
         price: nil,
         price_bnb: nil,
         call_id: 7,
         symbol: nil,
         transactions: []
       }

this test passes, however the Contract struct includes more keys than listed here in the test, how can I make this test fail if not all keys are provided?

1

There are 1 answers

2
Aleksei Matiushkin On

Use pattern matching in ExUnit.Assertions.assert/1 instead of equality check.

assert %Contract{
         contract: "0x3D29" <> _,
         name: "bla",
       } = Contract.fetch(contract: valid_address)