-
Notifications
You must be signed in to change notification settings - Fork 0
/
texture-loader.spec.js
60 lines (53 loc) · 1.75 KB
/
texture-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
50
51
52
53
54
55
56
57
58
59
60
jest.mock('three')
import { TextureLoader as THREETextureLoader } from 'three'
import { TextureLoader, TextureLoaderError } from '~/models/texture-loader.js'
describe('TextureLoader', () => {
let loader
describe('constructor(args)', () => {
let args, mockLoader
beforeEach(() => {
args = 'mock-args'
mockLoader = {}
THREETextureLoader.mockImplementation(() => mockLoader)
})
it('initializes ._loader with args', () => {
loader = new TextureLoader(args)
expect(THREETextureLoader).toHaveBeenCalledWith(args)
expect(loader._loader).toBe(mockLoader)
})
})
describe('load(url)', () => {
let url, result
beforeEach(() => {
loader = new TextureLoader()
url = 'http://example.com'
})
afterEach(() => {
// eslint-disable-next-line jest/no-standalone-expect
expect(loader._loader.load).toHaveBeenCalledWith(
url,
expect.any(Function),
expect.any(Function),
expect.any(Function)
)
})
describe('when super.load() succeeds', () => {
it('resolves with a Texture object', async () => {
let mockTexture = 'mock texture'
loader._loader.load =
jest.fn((url, onLoad, onProgress, onError) => onLoad(mockTexture))
result = loader.load(url)
await expect(result).resolves.toBe(mockTexture)
})
})
describe('when super.load() fails', () => {
it('rejects with a TextureLoaderError containing the error', async () => {
let mockError = new Error('mock error')
loader._loader.load =
jest.fn((url, onLoad, onProgress, onError) => onError(mockError))
result = loader.load(url)
await expect(result).rejects.toThrow(TextureLoaderError)
})
})
})
})