Adding and running tests

In test-driven development, we write tests before writing code. This way, we can observe when a test fails, add new code, and then see that the test passes, verifying that our change has the intended effect.

Let's start by testing the child selector that we used in Chapter 2, Selecting Elements, to add a horizontal class to all <li> elements that are children of <ul id="selected-plays">:

QUnit.test('Child Selector', (assert) => {  assert.expect(1);  const topLis = $('#selected-plays > li.horizontal');  assert.equal(topLis.length, 3, 'Top LIs have horizontal class');}); 
Listing A.2

We're testing our ability to select elements on the page, so we use the assert  assert.equal() test to compare the number of top-level ...

Get Learning jQuery 3 - Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.