<ul>
<li class="item"><span>item 1</span></li>
<li class="item">
<span>item 2</span>
<ul class="list">
<li>items</li>
<li>items</li>
<li>items</li>
<li>items</li>
<li>items</li>
</ul>
</li>
<li class="item"><span>item 3</span></li>
<li class="item"><span>item 4</span></li>
<li class="item"><span>item 5</span></li>
</ul>
const itemsEl = document.querySelectorAll('.item')
itemsEl.forEach(el => {
el.querySelector('.list') ? el.classList.add('test') : null
})