How to use ^ operator in testing assert function

my_topic = "my_topic" <> user.id

    assert_receive %Phoenix.Socket.Broadcast{
        topic: ^my_topic,
        event: "update",
        payload: %{id: ^user.id, status: "ongoing"}
      }

I got an error

invalid argument for unary operator ^, expected an existing variable, got: ^user.id

How can I insert value to assert function in test?

1 Like

You can only use ^ with variables. First bind the expression to a variable and then match it:

var = user.id
assert ^var = value
3 Likes