当我按照jest-expo-puppeteer 文档jest-expo-puppeteer
中的指南运行一个非常简单的示例测试时,我不断收到奇怪错误的日志,而且似乎找不到任何预期的元素。所以我尝试打印出页面:
// Import the config so we can find the host URL
import config from '../../jest-puppeteer.config'
let response
beforeEach(async () => {
// Jest puppeteer exposes the page object from Puppeteer
response = await page.goto(config.url)
})
it(`should have welcome string`, async () => {
const html = await page.evaluate(() => document.documentElement.outerHTML)
console.log(html)
await expect(page).toMatchElement('div[data-testid="welcome"]', { text: 'Welcome!' })
})
页面结果显示文本Oh no! It looks like JavaScript is not enabled in your browser.
:
...
<body>
<!--
A generic no script element with a reload button and a message.
Feel free to customize this however you'd like.
-->
<noscript>
<form
action=""
style="background-color:#fff;position:fixed;top:0;left:0;right:0;bottom:0;z-index:9999;"
>
<div
style="font-size:18px;font-family:Helvetica,sans-serif;line-height:24px;margin:10%;width:80%;"
>
<p>Oh no! It looks like JavaScript is not enabled in your browser.</p>
<p style="margin:20px 0;">
<button
type="submit"
style="background-color: #4630EB; border-radius: 100px; border: none; box-shadow: none; color: #fff; cursor: pointer; font-weight: bold; line-height: 20px; padding: 6px 16px;"
>
Reload
</button>
</p>
</div>
</form>
</noscript>
<!-- The root element for your Expo app. -->
<div id="root"><div class="css-view-1dbjc4n r-flex-13awgt0 r-pointerEvents-12vffkv"><div class="css-view-1dbjc4n r-flex-13awgt0 r-pointerEvents-12vffkv"></div></div></div>
<script src="/static/js/bundle.js"></script>
</body></html>
...
无头执行和浏览器内执行都会发生这种情况。
所以看起来Javascript已关闭。该page
对象是由内部创建的jest-expo-puppeteer
,所以我想知道:
- 如何在 中打开 JavaScript
jest-expo-puppeteer
? - 默认情况下不应该打开吗?也许我在设置中错过了一些东西?