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
fireEvent.setAutoDetectChanges(true);
7
8
expect(scene.children.length).toEqual(1);
9
const mesh = scene.children[0] as Mesh;
10
expect(mesh.isMesh).toEqual(true);
11
12
expect(material.color.getHexString()).toEqual('ffa500');
13
14
await fireEvent(mesh, 'pointerover');
15
expect(material.color.getHexString()).toEqual('ff69b4');
16
17
await fireEvent(mesh, 'pointerout');
18
expect(material.color.getHexString()).toEqual('ffa500');
19
20
await fireEvent(mesh, 'click');
21
expect(mesh.scale.toArray()).toEqual([1.5, 1.5, 1.5]);
22
23
expect(mesh.rotation.x).toEqual(0);
24
await advance(1);
25
26
// the cube should have rotated by 0.01 on the X axis since we advanced 1 frame
27
expect(mesh.rotation.x).toEqual(0.01);
28
});
29
});