Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Typescript 当使用Puppeter和jest进行测试时,canvas.getContext(“webgl”)返回null_Typescript_Jestjs_Puppeteer_Jest Image Snapshot - Fatal编程技术网

Typescript 当使用Puppeter和jest进行测试时,canvas.getContext(“webgl”)返回null

Typescript 当使用Puppeter和jest进行测试时,canvas.getContext(“webgl”)返回null,typescript,jestjs,puppeteer,jest-image-snapshot,Typescript,Jestjs,Puppeteer,Jest Image Snapshot,我正在尝试为使用jest、Puppeter和jest图像快照编写的webgl渲染器编写快照测试。我测试它的方式是,我编写了一个react TestApp,其中包含画布,如下所示: 导出函数TestApp(props:{width:number;height:number}):JSX.Element{ 返回( ); } 我需要为渲染器提供渲染场景时所需的WebGLRenderingContext。因此,在每次测试之前,我要做以下工作: beforeach(异步()=>{ div=document

我正在尝试为使用jest、Puppeter和jest图像快照编写的webgl渲染器编写快照测试。我测试它的方式是,我编写了一个react TestApp,其中包含画布,如下所示:

导出函数TestApp(props:{width:number;height:number}):JSX.Element{
返回(
);
}
我需要为渲染器提供渲染场景时所需的WebGLRenderingContext。因此,在每次测试之前,我要做以下工作:

beforeach(异步()=>{
div=document.createElement(“div”);
文件.正文.附件(div);
ReactDOM.render(,div);
const canvas:htmlcanvaseElement=document.getElementById(“绘制画布湿”);
webglRenderer=新的webglRenderer(canvas.getContext(“webgl”));
TestPlayerly=新的TestPlayerly(webglRenderer);
});

每当我调用canvas.getContext(“webgl”)时,返回的WebGLRenderingContext为null。以前有人有过这个问题吗

这不是通过React访问呈现的DOM元素的方式。你需要使用并等待它们被使用。您是否真的需要React元素,或者您只是在寻找获取canvas元素的方法?我正在获取canvas,但没有获取webgl渲染上下文。我确实需要React元素,因为我的应用程序就是这样设置的。如果您使用React,则需要等待元素装入后再使用。元素正在装入,但我仍然无法获取webgl渲染上下文。