我不知道为什么我会犯这个错误。我称之为
done()
功能和定义
jasmine.DEFAULT_TIMEOUT_INTERVAL
. 为什么它会抛出这个错误。
超时-异步回调未在jasmine.default_timeout_interval指定的超时内调用。
describe('Puppeteer', () => {
let originalTimeout;
beforeEach(function () {
originalTimeout = jasmine.DEFAULT_TIMEOUT_INTERVAL;
jasmine.DEFAULT_TIMEOUT_INTERVAL = 10000;
});
it('Logs in, redirects and does something', async (done) => {
const browser = await puppeteer.launch({
headless: true,
args: [
'--incognito'
]
});
const page = await browser.newPage();
await page.goto('localhost:3000/login');
... // Login Credentials
await page.waitForNavigation({ waitUntil: 'load' }); // redirects
... // perform some action on website
expect(a < b)
.toEqual(true);
browser.close();
done();
});
afterEach(function () {
jasmine.DEFAULT_TIMEOUT_INTERVAL = originalTimeout;
});
});
什么也做不了
describe('...', () => {
it('...', async (done) => {
....
}, 10000);
});
用这种方式写是可行的,但为什么呢?
describe('Puppeteer', () => {
it('Logs in, redirects and does something', () => {
(async () => {
const browser = await puppeteer.launch({
headless: true,
args: [
'--incognito'
]
});
....
expect(a < b)
.toEqual(true);
browser.close();
})();
});
});