Skip to content

Add example for testing systems that use events. #4936

Closed
@its-danny

Description

@its-danny

I couldn't find any good examples of this. Got some help on the Discord and it seems to work, but would be nice to have some clear examples. Could potentially extend this example.

fn test() {
    let mut app = App::new();

    app.add_event::<NetworkInput>();
    app.add_event::<NetworkOutput>();
    app.add_system(super::do_things);

    app.world
        .resource_mut::<Events<NetworkInput>>()
        .send(NetworkInput {
            // ...
        });

    app.update();

    let output_events = app.world.resource::<Events<NetworkOutput>>();
    let mut output_reader = output_events.get_reader();
    let output = output_reader.iter(&output_events).next().unwrap();

    // assert on `output`
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-DiagnosticsLogging, crash handling, error reporting and performance analysisC-ExamplesAn addition or correction to our examplesD-TrivialNice and easy! A great choice to get started with Bevy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions