NgtTestBed
NgtTestBed
is a utility from angular-three/testing
that abstracts TestBed
to make it easier to test our scene graph components.
create()
NgtTestBed
exposes a single static method create
that accepts a Component class and returns an object with the following properties:
Options
create
accepts an optional second argument that allows us to pass in options to customize the TestBed
.
-
canvasConfiguration
is an object whose role is similar toNgtCanvas
inputs. -
mockCanvasOptions
is an object that allows us to customize the mocked canvas element. It acceptswidth
andheight
as well asbeforeReturn
which is a function that allows us to return a mockedHTMLCanvasElement
before theTestBed
is created.
Example Scenario
For this example, we will use scene
, fireEvent
, and advance
to test the SceneGraph
component.
scene
allows us to assert the state of the scene graphfireEvent
allows us to fire events on the cubeadvance
allows us to advance the animation loop manually per frame
With scene
, we can assert the state of the scene graph. We can assert
however we want to. To keep things simple, we will just assert that the root Scene has a child which is a Mesh
Next, we will test the Mesh
events with fireEvent