因此,基本上,我正在为我的应用程序编写测试,我想在伪造者浏览器的上下文中运行一个函数。这是我尝试过的:
测试代码:
const printBlah = () => {
console.log('blah');
};
describe('Printing blah', () => {
it('Should print "blah".', async () => {
await page.evaluate(() => printBlah());
});
});
我得到的错误:
1) Printing blah
Should print "blah".:
Error: Evaluation failed: ReferenceError: printBlah is not defined
at __puppeteer_evaluation_script__:1:16
at ExecutionContext._evaluateInternal (node_modules/puppeteer/lib/ExecutionContext.js:93:19)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at ExecutionContext.evaluate (node_modules/puppeteer/lib/ExecutionContext.js:32:16)
-- ASYNC --
at ExecutionContext.<anonymous> (node_modules/puppeteer/lib/helper.js:82:19)
at DOMWorld.evaluate (node_modules/puppeteer/lib/DOMWorld.js:111:24)
-- ASYNC --
at Frame.<anonymous> (node_modules/puppeteer/lib/helper.js:82:19)
at Page.evaluate (node_modules/puppeteer/lib/Page.js:792:47)
at Page.<anonymous> (node_modules/puppeteer/lib/helper.js:83:27)
at /mnt/repos/r/p/src/p/index.spec.ts:124:16
at step (src/p/index.spec.ts:33:23)
at Object.next (src/p/index.spec.ts:14:53)
at /mnt/repos/r/p/src/p/index.spec.ts:8:71
at new Promise (<anonymous>)
at __awaiter (src/p/index.spec.ts:4:12)
at Context.<anonymous> (src/p/index.spec.ts:123:30)
at processImmediate (internal/timers.js:456:21)