Skip to content

Commit

Permalink
Add failing test case for incorrect WorldEntityMut behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
nakedible authored Nov 3, 2024
1 parent 5656166 commit 90f42bc
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions crates/bevy_ecs/src/world/entity_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4428,4 +4428,24 @@ mod tests {
.map(|_| { unreachable!() })
);
}

#[derive(Event)]
struct TestEvent;

#[test]
fn adding_observer_updates_location() {
let mut world = World::new();
let entity = world.spawn_empty().observe(|trigger: Trigger<TestEvent>, mut commands: Commands| {
commands.entity(trigger.entity()).insert(TestComponent(0));
}).id();

// this should not be needed, but currently calling `observe` does not flush commands
world.flush();

let mut a = world.entity_mut(entity);
a.trigger(TestEvent); // this adds command to change entity archetype
a.observe(|_: Trigger<TestEvent>| {}); // this flushes commands implicitly by spawning
let location = a.location();
assert_eq!(world.entities().get(entity), Some(location));
}
}

0 comments on commit 90f42bc

Please sign in to comment.