Add observer_no_target
test back
This commit is contained in:
parent
21602eab7f
commit
f17ecc8d89
@ -527,6 +527,11 @@ mod tests {
|
|||||||
#[component(storage = "SparseSet")]
|
#[component(storage = "SparseSet")]
|
||||||
struct S;
|
struct S;
|
||||||
|
|
||||||
|
#[derive(EntityEvent)]
|
||||||
|
struct EventA;
|
||||||
|
|
||||||
|
impl BroadcastEvent for EventA {}
|
||||||
|
|
||||||
#[derive(EntityEvent)]
|
#[derive(EntityEvent)]
|
||||||
struct EntityEventA;
|
struct EntityEventA;
|
||||||
|
|
||||||
@ -839,6 +844,28 @@ mod tests {
|
|||||||
assert_eq!(vec!["add_ab"], world.resource::<Order>().0);
|
assert_eq!(vec!["add_ab"], world.resource::<Order>().0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn observer_no_target() {
|
||||||
|
let mut world = World::new();
|
||||||
|
world.init_resource::<Order>();
|
||||||
|
|
||||||
|
let system: fn(On<EventA>) = |_| {
|
||||||
|
panic!("Trigger routed to non-targeted entity.");
|
||||||
|
};
|
||||||
|
world.spawn_empty().observe(system);
|
||||||
|
world.add_observer(move |obs: On<EventA>, mut res: ResMut<Order>| {
|
||||||
|
assert_eq!(obs.target(), Entity::PLACEHOLDER);
|
||||||
|
res.observed("event_a");
|
||||||
|
});
|
||||||
|
|
||||||
|
// TODO: ideally this flush is not necessary, but right now observe() returns WorldEntityMut
|
||||||
|
// and therefore does not automatically flush.
|
||||||
|
world.flush();
|
||||||
|
world.trigger(EventA);
|
||||||
|
world.flush();
|
||||||
|
assert_eq!(vec!["event_a"], world.resource::<Order>().0);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn observer_entity_routing() {
|
fn observer_entity_routing() {
|
||||||
let mut world = World::new();
|
let mut world = World::new();
|
||||||
|
Loading…
Reference in New Issue
Block a user