DevTools/mochitests coding standards: Difference between revisions

Jump to navigation Jump to search
Remove content DOM node access in example since that wouldn't work with e10s.
(Removing the custom asyncTest function with the native add_task)
(Remove content DOM node access in example since that wouldn't work with e10s.)
Line 150: Line 150:


   const TESTS = [
   const TESTS = [
     {desc: "add a class", cssSelector: "#id1", mutate: function() {...}, expectedAttributes: {class: "c"}},
     {desc: "add a class", cssSelector: "#id1", makeChanges: function*() {...}},
     {desc: "change href", cssSelector: "a.the-link", mutate: function() {...}, expectedAttributes: {href: "..."}},
     {desc: "change href", cssSelector: "a.the-link", makeChanges: function*() {...}},
     ...
     ...
   ];
   ];
Line 161: Line 161:
       info("Testing step: " + step.desc);
       info("Testing step: " + step.desc);
       yield selectNode(desc.cssSelector, inspector);
       yield selectNode(desc.cssSelector, inspector);
       desc.mutate();
       yield desc.makeChanges();
      assertExpectedAttributes(getNode(desc.cssSelector, desc.expectedAttributes);
     }
     }
   });
   });
 
  function assertExpectedAttributes(node, attrs) {
    ...
  }


As shown in this code example, you can add as many test cases as you want in the TESTS array and the actual test code will remain very short, and easy to understand and maintain (note that when looping through test arrays, it's always a good idea to add a "desc" property that will be used in an info() log output).
As shown in this code example, you can add as many test cases as you want in the TESTS array and the actual test code will remain very short, and easy to understand and maintain (note that when looping through test arrays, it's always a good idea to add a "desc" property that will be used in an info() log output).
130

edits

Navigation menu