0
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?

John Smith
  • 1,726
  • 2
  • 18
  • 30
  • What do you mean by "not provided"? Do you mean `nil`? Or do you mean "not present on the struct". Because keys are _always_ present on the struct. – Peaceful James May 02 '21 at 15:39

1 Answers1

0

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

assert %Contract{
         contract: "0x3D29" <> _,
         name: "bla",
       } = Contract.fetch(contract: valid_address)
Everett
  • 8,746
  • 5
  • 35
  • 49
Aleksei Matiushkin
  • 119,336
  • 10
  • 100
  • 160