Skip to content

advance

advance is a method on NgtTestBed that allows us to advance frame to run animations in the scene graph.

advance(frames, delta)

advance accepts two arguments:

  • frames is the number of frames to advance
  • delta 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 this example, we will use advance to test the animations.

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] as Mesh;
expect(mesh.isMesh).toEqual(true);
expect(material.color.getHexString()).toEqual('ffa500');
await fireEvent(mesh, 'pointerover');
expect(material.color.getHexString()).toEqual('ff69b4');
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 we advanced 1 frame
expect(mesh.rotation.x).toEqual(0.01);
});
});