[英]unit test the javascript functions in my django application
I have a Django app, which contains backend logic in views.py
and front end logic/user data processing written in javascript and jQuery inside HTML files.我有一个 Django 应用程序,它包含
views.py
中的后端逻辑和 HTML 文件中用 javascript 和 jQuery 编写的前端逻辑/用户数据处理。 Now I wanted to write unit tests, can I use mocha-chai for doing this or any other alternative to do unit testing a JavaScript code in Django.现在我想编写单元测试,我可以使用 mocha-chai 来做这个或任何其他替代方法来在 Django 中对 JavaScript 代码进行单元测试。
my directory structure我的目录结构
myapp
--->templates
----->base.html
----->home.html
base.html contains: base.html 包含:
<html>
<body>
<h1>WElcome</h1>
<script>
function myfunc(){
console.log("welcome")
//some user logic
}
</sctipt>
which framework to use in order to do write a unit test case for this 'myfunc' inside the Django template使用哪个框架来为 Django 模板中的“myfunc”编写单元测试用例
We have tried the following:我们尝试了以下方法:
We failed, however, to get it to work completely because the headless browser did not run all of our JS code.然而,我们没有让它完全工作,因为无头浏览器没有运行我们所有的 JS 代码。 This was some years ago, and the libraries surely have evolved since then.
那是几年前的事了,从那时起图书馆肯定已经发展了。
If you are happy with integration tests only:如果您只对集成测试感到满意:
Setup the selenium with Django LiveServerTestCase and a headless browser that runs all of your JS code correctly.使用 Django LiveServerTestCase 和可正确运行所有 JS 代码的无头浏览器设置 selenium。
https://docs.djangoproject.com/en/2.2/topics/testing/tools/#liveservertestcase https://docs.djangoproject.com/en/2.2/topics/testing/tools/#liveservertestcase
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.