Jest Test функция привязки - PullRequest
       8

Jest Test функция привязки

0 голосов
/ 28 февраля 2019

Как можно связать кого-ток тестовой функции, выполняемой 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)
});

Но this - это undefined при запускешуткой.

Ответы [ 2 ]

0 голосов
/ 04 марта 2019
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>
0 голосов
/ 01 марта 2019

Оказывается, Jest предоставляет встроенный помощник, чтобы сделать именно это:

describe.each([1,2])('test', x => {
    test(`test ${x}`, function() {
        console.log('x', x)
    });
})
...