我有一个index.html文件:
<!doctype html>
<html>
<head>
<style>
#container {width: 600px; max-width: 100%; margin: 1em auto;}
</style>
</head>
<body>
<div id="container">
<form>
<input type="text" id="text" placeholder="enter some text" required maxlength="10" pattern="^[a-z,A-Z]{1,10}$"><br />
<input type="text" id="number" placeholder="enter a number" required maxlength="10" pattern="\d{10}"><br />
<input type="submit">
</form>
</div>
</body>
</html>
我想在表单上使用chai asserts进行摩卡测试。
当我测试外部.js
文件时,可以使用require
语句提取该.js
文件。
如何引用/导入.html
文件以在表单上运行测试?
我无法使用Google搜索找到此类信息。
帮助表示赞赏。
编辑:我是否在<script>
文件内的.html
中运行测试?
答案 0 :(得分:1)
我想我已经找到了答案。
我可以在html文件中使用以下内容。
<div id="mocha"></div>
<script src="node_modules/mocha/mocha.js"></script>
<script src="node_modules/chai/chai.js"></script>
<script>mocha.setup('bdd')</script>
<!-- load code you want to test here -->
<!-- load your test files here -->
<script>
mocha.run();
</script>
来自this page。