MikeSchulze / gdUnit4

A Godot Unit Test Framework. Support for GDScript and C# unit testing
MIT License
565 stars 30 forks source link

GD-553: Add support for finding a node by path #553

Closed sparqyeti closed 1 month ago

sparqyeti commented 1 month ago

Is your feature request related to a problem? Please describe. When searching the scene tree some nodes have the same name making find_child() function return only one of the possible nodes

Describe the solution you'd like An alternative would be to give an API which returns a node of a particular path instead of node name

Describe alternatives you've considered Using get_tree and other methods are a work around to build a path from.

Additional context N/A

MikeSchulze commented 1 month ago

You can use already get_node in your tests. e.g.

func test_find_by_path() -> void:
    var node_a :Node3D = auto_free(Node3D.new())
    node_a.set_name("node_a")
    var node_b :Node3D = auto_free(Node3D.new())
    node_b.set_name("node_b")
    var node_c :Node3D = auto_free(Node3D.new())
    node_c.set_name("node_c")
    add_child(node_a, true)
    node_a.add_child(node_b, true)
    node_b.add_child(node_c, true)

    assert_that(get_node(node_a.get_path())).is_same(node_a)
    assert_that(get_node(node_b.get_path())).is_same(node_b)
    assert_that(get_node(node_c.get_path())).is_same(node_c)