QA Graphic

Map - Jquery

Find the contents order using JQuery Map

jQuery map() function is useful when you want to verify that a list (unordered, ordered) are in the right order. Simple create the jQuery object as a Map array and then join it.

Sample Data

<div>
      <label for="two">2</label>
      <input type="checkbox" value="2" id="Boston" name="number[]">
    </div>
    <div>
      <label for="four">4</label>
      <input type="checkbox" value="4" id="Concord" name="number[]">
    </div>
    <div>
      <label for="six">6</label>
      <input type="checkbox" value="6" id="Stow" name="number[]">
    </div>
    <div>
      <label for="eight">8</label>
      <input type="checkbox" value="8" id="Carlisle" name="number[]">
</div>

Your jQuery Action

$( ":checkbox" )
  .map(function() {
    return this.id;
  })
  .get()
  .join();

Your Results would be:

"Boston,Concord,Stow,Carlisle"

Javascript results:

 return $( ":checkbox" )
  .map(function() {
    return this.id;
  })
  .get()
  .join()
  .includes("Boston,Concord,Stow,Lowell")

 

About

jQuery is the most popular Javascript library on the Internet. Chances are that websites that your testing use it. These posts are all about tips and tricks for QA testing.

Schedule

Sunday 16 Misc
Monday 17 Media
Tuesday 18 QA
Wednesday 19 Pytest
Thursday 20 PlayWright
Friday 21 Macintosh
Saturday 22 Internet Tools