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.
1
const { fixture, advance } = NgtTestBed.create(SceneGraph);
2
3
await advance(1);
4
// assert the scene graph state after 1 frame

Example Scenario

For this example, we will use advance to test the animations.

1
import { NgtTestBed } from 'angular-three/testing';
2
3
describe('SceneGraph', () => {
4
it('should render', async () => {
5
const { scene, fireEvent, advance } = NgtTestBed.create(SceneGraph);
6
7
expect(scene.children.length).toEqual(1);
8
const mesh = scene.children[0] as Mesh;
9
expect(mesh.isMesh).toEqual(true);
10
11
expect(material.color.getHexString()).toEqual('ffa500');
12
13
await fireEvent(mesh, 'pointerover');
14
expect(material.color.getHexString()).toEqual('ff69b4');
15
16
await fireEvent(mesh, 'pointerout');
17
expect(material.color.getHexString()).toEqual('ffa500');
18
19
await fireEvent(mesh, 'click');
20
expect(mesh.scale.toArray()).toEqual([1.5, 1.5, 1.5]);
21
22
expect(mesh.rotation.x).toEqual(0);
23
await advance(1);
24
25
// the cube should have rotated by 0.01 on the X axis since we advanced 1 frame
26
expect(mesh.rotation.x).toEqual(0.01);
27
});
28
});