javascript - Using Jest to test scripts affecting the DOM
问题描述
I have a script that translated markdown to html on a document and I'm trying to test the html rending. Here's what I have so far.
<html>
<head>
<script
type="text/javascript"
src="https://rawcdn.githack.com/oscarmorrison/md-page/master/md-page.js"
></script>
</head>
<body>
<noscript># hello</noscript>
</body>
</html>
Here's my Jest file.
describe("HTML Rendering Tests: Ensures that syntax is converted successfully.", () => {
beforeAll(() => {
const s = document.createElement("script");
s.type = "text/javascript";
s.src = "https://rawcdn.githack.com/oscarmorrison/md-page/master/md-page.js";
document.head.appendChild(s);
});
test('it should load scripts', () => {
document.body.innerHTML = '<noscript># hello';
expect(document.body).toContain('Hello');
});
});
I've printed everything inside it doesn't seem to be translating the text to markdown. Any thoughts?
<head><script type="text/javascript" src="https://rawcdn.githack.com/oscarmorrison/md-page/master/md-page.js"></script></head><body><noscript># hello</noscript></body>
解决方案
推荐阅读
- sql - SQL - 在两行或多行上满足该值的条件时返回值
- laravel-5 - php artisan route:list ReflectionException 类不存在但它在那里?
- amazon-web-services - 如何查看用户的所有 AWS IAM 权限?
- excel - 将 Excel VBA 中具有临时名称的选项卡另存为单独的 csv 文件
- excel - 如何使用分隔符连接多个单元格(仅当单元格不为空白时)?
- c++ - C++17中的部分类模板参数推导
- shell - 编写警报脚本
- python - 使用类来组织共享输入的功能是否合适?
- python-2.7 - 更新 Lambda 脚本以更改实例大小
- c# - 统一构建游戏后tcp网络无法正常工作