Skip to content

Commit a68b85d

Browse files
committed
add tograph doc
1 parent 63ac412 commit a68b85d

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: toGraph
3+
description: Details about the Angular Three Testing `toGraph` function
4+
---
5+
6+
`toGraph` is a function that allows you to convert a THREE.js object into a simple `NgtTestGraphObject`.
7+
8+
This is useful for snapshot testing as it _at least_ provides the scene graph structure.
9+
10+
:::caution
11+
12+
In many cases, we can use `toJSON` on the THREE.js object to better structure. However, this is not always possible
13+
14+
- The `uuid` property will always be different for each test run making it difficult to do snapshot testing
15+
- Some THREE.objects do not have `toJSON` method and will throw an error when we try to call `scene.toJSON()` from the root
16+
17+
:::
18+
19+
```ts
20+
const { fixture, toGraph } = NgtTestBed.create(SceneGraph);
21+
fixture.detectChanges();
22+
23+
expect(toGraph()).toMatchSnapshot();
24+
25+
/**
26+
* For a scene with a single mesh
27+
*
28+
* [
29+
* {
30+
* "type": "Mesh",
31+
* "name": "",
32+
* "children": []
33+
* }
34+
* ]
35+
*/
36+
```
37+
38+

0 commit comments

Comments
 (0)