【问题标题】:No message matching on assert_push using phoenix channels使用凤凰频道的 assert_push 没有消息匹配
【发布时间】:2020-12-15 16:04:38
【问题描述】:
     No message matching %Phoenix.Socket.Message{event: "initialize", payload: %{new_player: ^new_player, ref: nil, topic: "game:subtopic"}} after 100ms.
 The following variables were pinned:
   new_player = %Player.State{hp: %{current: 10, max: 10}, position: %{target_x: 0, target_z: 0, x: 0, z: 0}, socket_id: "user_id", username: nil}
 Process mailbox:
   %Phoenix.Socket.Message{event: "initialize", join_ref: 714, payload: %{new_player: %Player.State{hp: %{current: 10, max: 10}, position: %{target_x: 0, target_z: 0, x: 0, z: 0}, socket_id: "user_id", username: nil}}, ref: nil, topic: "game:subtopic"}

测试代码:

new_player = World.player_state(socket.id)

assert_push "initialize",
            %{new_player: ^new_player, ref: nil, topic: "game:subtopic"},
            100

我不确定为什么测试失败。我试着不固定新玩家。我看到的唯一区别是 join_ref 不是我的测试中返回的结构的一部分。

我不明白!

【问题讨论】:

  • 哦,可能是我在测试中使用了结构体!哎呀。

标签: elixir phoenix-framework


【解决方案1】:

以下两个字段实际上不是payload 的一部分,而是Phoenix.Socket.Message 的一部分,这就是我认为它不匹配的原因:ref: nil, topic: "game:subtopic"

如果你删除这两个它应该匹配。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-10
    • 2017-03-07
    • 2021-01-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 2018-06-21
    相关资源
    最近更新 更多