Dispatch Events

Recommended Posts


I'd like to develop some automated UI tests for my PixiJS application (PixiJS 4.8.1). My test procedure should look something like this later:

const test = new UITest(){x: 100, y: 80})
test.drag({x: 100, y: 80}, {x: 120, y: 40})
test.dblClick({x: 200, y: 120})


For this I have to trigger events. I know that the InteractionManager and DisplayObject inherit from EventEmitter. Which option is the best way to trigger events?

1. directly on the canvas element?

const originalEvent = new MouseEvent('click', {
    bubbles: true,
    cancelable: true,


2. or via app.renderer.plugins.interaction.onPointerUp (originalEvent) for example?

3. or via app.renderer.plugins.interaction.emit(originalEvent)


Unfortunately, I have not yet managed to trigger an event with these three ways 😞


What already worked was to call the emit method directly on a PIXI.DisplayObject, but I needed to create a PIXI.InteractionEvent object myself, which was quite expensive ...


Thanks in advance!



Share this post

Link to post
Share on other sites

I've looked into the sources, but still don't know if it's best to use 

app.renderer.plugins.interaction.emit('pointerup', originalEvent)




But I think both should work, or not?


Edited by Siddi

Share this post

Link to post
Share on other sites

Depends on what you want to test. If you want to test your code and assume the interaction manager works, then dispatch events from the interaction manager. If you want to test that the interaction manager works, and that your code works using it, then dispatch mouse events onto the canvas. The second is also more similar to what "a user would do".

Share this post

Link to post
Share on other sites

I assume that the interaction manager works, and want to test my own code. 

I found a solution for me. I fire standard JavaScript events (MouseEvent and PointerEvent) directly on the canvas element. The rest (triggering the events on a certain DisplayObject) then takes over pixi for me. It is easier than expected 🙂, thank you!

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.