gpt4 book ai didi

node.js - Jasmine 不与 puppeteer 师合作

转载 作者:太空宇宙 更新时间:2023-11-03 22:50:24 24 4
gpt4 key购买 nike

我正在尝试使用 puppeteer 在 jasmine 中运行一个简单的测试,但是当我在测试脚本中使用它时,我无法让 puppeteer 工作:

const puppeteer = require('puppeteer');

describe("Jasmine puppeteer", function() {

let browser;
let page;

beforeAll(() => {
browser = await puppeteer.launch({headless: false});
page = await browser.newPage();
await page.goto('chrome://newtab');
await page.screenshot({path: 'a.png'});
})

it("jasmine puppeteer", () => {
expect(await page.title()).toBe("");
done();
});

afterAll(() => {
})
});

运行此脚本时我得到:

$ npm test spec/testspec.js

> test@0.0.1 test D:\sample
> jasmine "spec/testspec.js"

D:\sample\spec\testspec.js:10
browser = await puppeteer.launch({headless: false});
^^^^^^^^^

SyntaxError: Unexpected identifier
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:607:28)
at Object.Module._extensions..js (module.js:654:10)
at Module.load (module.js:556:32)
at tryModuleLoad (module.js:499:12)
at Function.Module._load (module.js:491:3)
at Module.require (module.js:587:17)
at require (internal/module.js:11:18)
at D:\sample\node_modules\jasmine\lib\jasmine.js:93:5
npm ERR! Test failed. See above for more details.

npm test 只是指向 jasmine。如果我评论 puppeteer 相关代码,测试工作正常。

最佳答案

await 仅适用于异步函数

beforeAll((done) => {
let screenshot = async function() {
browser = await puppeteer.launch({ headless: false });
page = await browser.newPage();
await page.goto('chrome://newtab');
await page.screenshot({ path: 'a.png' });
}
screenshot().then(done)
})

关于node.js - Jasmine 不与 puppeteer 师合作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48497986/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com