[英]Jest Test function bind
一个人怎么能绑定某些东西? 到 jest 执行的测试函数?
我想为不同的配置运行相同的一组测试两次,如下所示:
function wrap(title, fn) {
[1,2].forEach(x => {
this.hello = x
fn.bind(this)
fn() // works
test(title, fn) // does not work
})
}
wrap('test hello world', function() {
console.log('this.hello', this.hello)
});
但是当由 jest 运行时, this
是undefined
。
结果 jest 提供了一个内置的帮助程序来做到这一点:
describe.each([1,2])('test', x => {
test(`test ${x}`, function() {
console.log('x', x)
});
})
HTML CODE :
<!-- createNewAbout is my module name and submitAboutContent is the Controller You you can call it the backend function .
您也可以在表单操作中使用 URL。 --> 输入标题 输入描述 添加图片 提交
<!-- this is the function Which i am Calling . I am taking value of name attribute of button to disable button for multiple fuction call and also taking an array of values of name attribute of manditory fields. Here we cant use values of ID attribute so we have to use name . -->
<script>
function validationOnlySubmitForm(button_name="", arr="") {
var fields = arr, flag = 0;
document.getElementsByName(button_name)[0].setAttribute("disabled" , true);
for (var i = 0 ; i <= fields.length - 1 ; i++) {
if (document.getElementsByName(fields[i])[0].value.length == 0) {
flag = 1;
document.getElementsByName(fields[i])[0].focus();
alert(fields[i] + " is manditory.");
document.getElementsByName(button_name)[0].removeAttribute("disabled");
return false;
}
}
if (flag == 0)
return true;
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.