【发布时间】:2019-05-21 05:11:24
【问题描述】:
为了执行集成测试,我使用了jasmine 和puppeteer,由于我正在通过教育课程,据此,我决定使用 js 代理来封装测试功能,但是当我进行测试时,我会遇到以下错误
TypeError: Method Promise.prototype.then called on incompatible receiver [object Object]
这是我的 CustomPage 类,它将代表一个 chrome 选项卡: const puppeteer = require('puppeteer');
class CustomPage{
static async build(){
const browser =await puppeteer.launch({headless:false});
const page = browser.newPage();
var customPage = new CustomPage(page);
console.log("harchi run mishe")
return new Proxy(customPage,{
get:function(target,property){
return (customPage[property]||page[property]||browser[property])
}
})
//return proxy;
}
constructor(page){
this.page = page
}
}
module.exports=CustomPage;
这是我的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 不能将代理视为 Promise 但是我找不到任何解决方案。
【问题讨论】:
标签: javascript testing jasmine integration-testing puppeteer