我需要測試是否曾發生過window.location.href = data.redirect_path
。我怎麼會在Sinon中嘲笑這一點,而不把它從我的試飛員那裏轉移出去?我使用chai/mocha.js和茶匙作爲測試跑步者。使用mocha/chai的AJAX請求中的window.location.href的單元測試
$.ajax({
type: 'PUT',
url: $url,
dataType: 'json',
data: { user: $userData },
success: function(data) {
if (data.success == true) {
window.location.href = data.redirect_path
} else {
$errorsContainer.html(data.html);
$codeInput.select();
if (typeof data.redirect_path !== 'undefined') {
window.location.href = data.redirect_path
}
}
}
});