advance
advance
is a method on NgtTestBed
that allows you to advance frame to run animations in the scene graph.
advance(frames, delta)
advance
accepts two arguments:
frames
is the number of frames to advancedelta
is the delta time to use for the animations. It can be a number or an array of numbers.
const { fixture, advance } = NgtTestBed.create(SceneGraph);
await advance(1);
// assert the scene graph state after 1 frame
Example Scenario
For the example scenario, the cube rotates on the x-axis by 0.01 unit each frame. Knowing this, you can use advance
to advance the frames and assert the rotation value.
import { is } from 'angular-three';import { NgtTestBed } from 'angular-three/testing';
describe('SceneGraph', () => { it('should render', async () => { const { scene, fireEvent, advance } = NgtTestBed.create(SceneGraph);
expect(scene.children.length).toEqual(1); const mesh = scene.children[0]; expect(is.three<THREE.Mesh>(mesh, 'isMesh')).toEqual(true);
expect(material.color.getHexString()).toEqual('ffa500');
await fireEvent(mesh, 'pointerover'); expect(material.color.getHexString()).toEqual('a47bd5');
await fireEvent(mesh, 'pointerout'); expect(material.color.getHexString()).toEqual('ffa500');
await fireEvent(mesh, 'click'); expect(mesh.scale.toArray()).toEqual([1.5, 1.5, 1.5]);
expect(mesh.rotation.x).toEqual(0); await advance(1);
// the cube should have rotated by 0.01 on the X axis since advance moves up 1 frame expect(mesh.rotation.x).toEqual(0.01); });});