Skip to content

Commit

Permalink
improve docs spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
michealparks committed Jun 7, 2024
1 parent cf20eb4 commit 4968c61
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 27 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
pnpm-lock.yaml
package-lock.json
yarn.lock
README.md
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ import { render } from '@threlte/test'
import Scene from './Scene.svelte'

describe('Scene', () => {
it('creates a box mesh with a boxGeometry and meshStandardMaterial', () => {
const { scene } = render(Scene)

const mesh = scene.getObjectByProperty('isMesh', true) as Mesh
expect(mesh).toBeDefined()
expect(mesh.material).toBeInstanceOf(MeshStandardMaterial)
expect(mesh.geometry).toBeInstanceOf(BoxGeometry)
})
it('creates a box mesh with a boxGeometry and meshStandardMaterial', () => {
const { scene } = render(Scene)

const mesh = scene.getObjectByProperty('isMesh', true) as Mesh
expect(mesh).toBeDefined()
expect(mesh.material).toBeInstanceOf(MeshStandardMaterial)
expect(mesh.geometry).toBeInstanceOf(BoxGeometry)
})
})
```

Expand All @@ -27,13 +27,13 @@ Calling `render` will provide useful tools for testing your component's behavior

```ts
const {
component, // SvelteComponent
scene, // THREE.Scene
camera, // CurrentWritable<THREE.Camera>
advance, // (delta?: number) => void
fireEvent, // (object3D: THREE.Object3D, event, payload) => Promise<void>
rerender, // (props) => Promise<void>
unmount, // () => void
component, // SvelteComponent
scene, // THREE.Scene
camera, // CurrentWritable<THREE.Camera>
advance, // (delta?: number) => void
fireEvent, // (object3D: THREE.Object3D, event, payload) => Promise<void>
rerender, // (props) => Promise<void>
unmount, // () => void
} = render(Component)
```

Expand All @@ -56,7 +56,7 @@ If your component uses the `interactivity` plugin, you can test events using the

```svelte
<script lang="ts">
export let onClick
export let onClick
</script>
<T.Mesh on:click={onClick}>...</T.Mesh>
Expand All @@ -79,21 +79,23 @@ Note that if you use the event object, you will have to design a mock payload.

We recommend using `@threlte/test` with Vitest as your test runner. To get started, add the `threlteTesting` plugin to your Vite or Vitest config.

```diff
// vite.config.js
import { svelte } from '@sveltejs/vite-plugin-svelte'
+ import { threlteTesting } from '@threlte/test/vite'

export default defineConfig({
plugins: [
svelte(),
+ threlteTesting(),
]
});
```ts
// vite.config.js
import { svelte } from '@sveltejs/vite-plugin-svelte'
import { threlteTesting } from '@threlte/test/vite'

export default defineConfig({
plugins: [
svelte(),
threlteTesting(),
]
});
```

Additionally, the [Vitest environment](https://vitest.dev/guide/environment.html) must be set to a DOM enviroment.

If you are using Svelte Testing Library and its plugin, the `threlteTesting` plugin isn't needed as they have the same internals.

### Limitations

The test renderer runs in a node.js environment, and it does not attempt to mock a webgl canvas, which can become quite complicated. Instead, it creates a Threlte context and renders your component as a child of a Threlte `<SceneGraphObject>`. This means that testing `<Canvas>` or `WebGLRenderer` related configuration and behavior won't work.
Expand Down

0 comments on commit 4968c61

Please sign in to comment.