-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsetupFiles.js
38 lines (32 loc) · 1.07 KB
/
setupFiles.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
import "jest-canvas-mock";
import Adapter from "@wojtekmaj/enzyme-adapter-react-17";
import { configure } from "enzyme";
import expect from "expect";
import GL from "gl";
import { toBeDeepCloseTo, toMatchCloseTo } from "jest-matcher-deep-close-to";
import * as THREE from "three";
import { Wave } from "../src/wave";
import { ELEMENT_PROPERTIES } from "./enums";
import { createElement, HEIGHT, WIDTH } from "./utils";
// configure enzyme adapter
configure({ adapter: new Adapter() });
// extend jest expect
expect.extend({
toBeDeepCloseTo,
toMatchCloseTo,
});
/**
* mock WebGLRenderer by headless GL.
*/
Wave.prototype.getWebGLRenderer = (config) => {
const context = GL(WIDTH, HEIGHT, { preserveDrawingBuffer: true });
// create a canvas element with mocked width/height otherwise the default with 0 width is used.
const canvas = createElement("canvas", ELEMENT_PROPERTIES);
return new THREE.WebGLRenderer({
...config,
context,
canvas,
});
};
window.setImmediate = window.setTimeout;
window.clearImmediate = window.clearTimeout;