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()
})
})