diff --git a/crates/bevy_ecs/src/reactivity.rs b/crates/bevy_ecs/src/reactivity.rs index 6e0eb9fa0d..63c6724d21 100644 --- a/crates/bevy_ecs/src/reactivity.rs +++ b/crates/bevy_ecs/src/reactivity.rs @@ -136,7 +136,7 @@ mod tests { reactivity::{update_reactive_components, ReactiveComponentExpressions}, }; - #[derive(Component)] + #[derive(Component, PartialEq, Eq, Debug)] struct Foo(u32); #[derive(Component, PartialEq, Eq, Debug)] @@ -162,4 +162,32 @@ mod tests { assert_eq!(world.entity(sink).get::(), Some(&Bar(1))); } + + #[test] + fn test_reactive_component_chaining() { + let mut world = World::new(); + world.init_resource::(); + + let a = world.spawn(Foo(0)).id(); + let b = world + .spawn(ReactiveComponent::new(a, |foo: &Foo| Foo(foo.0 + 1))) + .id(); + let c = world + .spawn(ReactiveComponent::new(b, |foo: &Foo| Foo(foo.0 + 1))) + .id(); + + world.flush(); + + assert_eq!(world.entity(a).get::(), Some(&Foo(0))); + assert_eq!(world.entity(b).get::(), Some(&Foo(1))); + assert_eq!(world.entity(c).get::(), Some(&Foo(2))); + + world.get_mut::(a).unwrap().0 = 3; + + update_reactive_components(&mut world); + + assert_eq!(world.entity(a).get::(), Some(&Foo(3))); + assert_eq!(world.entity(b).get::(), Some(&Foo(4))); + assert_eq!(world.entity(c).get::(), Some(&Foo(5))); + } }