Unit test a method include scene.onAfterRenderObservable

I have a method that I need to do unit test, which include
scene.onAfterRenderObservable.add(() => {…}});

when I do unit test, I find scene.onAfterRenderObservable.add does not get called, I added scene.render(), but looks like it still does not get called, any idea?

Update:
This is the way I create engine and scene in my unit test
let engine = new NullEngine();
let scene = new Scene(engine);

It’s difficult to say without a repro, but what scene.onAfterRenderObservable.add(function); does is register a function to be called once the scene is done rendering (by adding it to the onAfterRenderObservable list). So on the render loop, you should expect function to be called, not the add method.

1 Like

@pigga as long as your test is defined in an asynchronous way it should be ok.

1 Like

I think it may help to assign the function to a variable instead of using an anonymous function, so it has a name:

const myFunction = () => { // do stuff };
scene.onAfterRenderObservable.add(myFunction);

I did test if the function inside scene.onAfterRenderObservable.add, but looks like it never entered this function

This method is not asynchronous, but it is inside another asynchronous method, maybe that’s the issue