Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/390.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.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
Javascript TypeError:方法Promise.prototype.then在不兼容的接收方代理上调用_Javascript_Testing_Jasmine_Integration Testing_Puppeteer - Fatal编程技术网

Javascript TypeError:方法Promise.prototype.then在不兼容的接收方代理上调用

Javascript TypeError:方法Promise.prototype.then在不兼容的接收方代理上调用,javascript,testing,jasmine,integration-testing,puppeteer,Javascript,Testing,Jasmine,Integration Testing,Puppeteer,为了执行集成测试,我使用了jasmine和puppeter,由于我通过了一门教育课程,因此,我决定使用js代理来封装测试功能,但当我进行测试时,我会遇到以下错误 TypeError: Method Promise.prototype.then called on incompatible receiver [object Object] 下面是我的CustomPage类,它将表示一个chrome选项卡: const puppeter=require('puppeter') 这是我的heade

为了执行集成测试,我使用了
jasmine
puppeter
,由于我通过了一门教育课程,因此,我决定使用js代理来封装测试功能,但当我进行测试时,我会遇到以下错误

TypeError: Method Promise.prototype.then called on incompatible receiver [object Object] 
下面是我的CustomPage类,它将表示一个chrome选项卡: const puppeter=require('puppeter')

这是我的
header.spec.js
文件,它是我的测试文件

const Page = require('./helpers/page');
var tab;

describe('header representation',()=>{
    beforeEach(async(done)=>{
        tab =await Page.build();****here is the problem********
        await tab.goto('localhost:3000');
    })

    it('should show header logo',async()=>{
        const text = await tab.$eval('a.brand-logo',(el)=>el.innerHTML);
        expect(text).toEqual('Blogster');
        //done()
    })
})

事实上,我认为我的问题在于指定的行。js似乎不能将代理视为承诺,但我找不到任何解决方案。

对于后代,我发现使用代理时,需要重新绑定javascript的
this
关键字。例如:

函数验证器(promise,prop){
如果(承诺中的支柱| |承诺拥有自己的财产(支柱)){
if(承诺类型[prop]=“功能”){
返还承诺[prop].bind(承诺)//
const Page = require('./helpers/page');
var tab;

describe('header representation',()=>{
    beforeEach(async(done)=>{
        tab =await Page.build();****here is the problem********
        await tab.goto('localhost:3000');
    })

    it('should show header logo',async()=>{
        const text = await tab.$eval('a.brand-logo',(el)=>el.innerHTML);
        expect(text).toEqual('Blogster');
        //done()
    })
})