-
Notifications
You must be signed in to change notification settings - Fork 0
/
gltf-loader.spec.js
49 lines (43 loc) · 1.45 KB
/
gltf-loader.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
jest.mock('three/examples/jsm/loaders/GLTFLoader.js')
import { GLTFLoader as THREEGLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
import { GLTFLoader } from '~/models/gltf-loader.js'
describe('GLTFLoader', () => {
let loader
it('extends THREE.GLTFLoader', () => {
expect(GLTFLoader.prototype).toBeInstanceOf(THREEGLTFLoader)
})
describe('parse(data)', () => {
let data, result
beforeEach(() => {
loader = new GLTFLoader()
data = 'mockData'
})
afterEach(() => {
// eslint-disable-next-line jest/no-standalone-expect
expect(THREEGLTFLoader.prototype.parse).toHaveBeenCalledWith(
data,
'/',
expect.any(Function),
expect.any(Function)
)
})
describe('when super.parse() succeeds', () => {
it('resolves with a GLTF object', async () => {
let mockGLTF = 'mock gltf'
THREEGLTFLoader.prototype.parse =
jest.fn((data, path, onLoad, onError) => onLoad(mockGLTF))
result = loader.parse(data)
await expect(result).resolves.toBe(mockGLTF)
})
})
describe('when super.parse() fails', () => {
it('rejects with the error', async () => {
let mockError = new Error('mock error')
THREEGLTFLoader.prototype.parse =
jest.fn((data, path, onLoad, onError) => onError(mockError))
result = loader.parse(data)
await expect(result).rejects.toThrow(mockError)
})
})
})
})