1.3.77 • Published 4 years ago

@htmlacademy/dom-check v1.3.77

Weekly downloads
27
License
MIT
Repository
github
Last release
4 years ago

@htmlacademy/dom-check

DomCheck is a node.js module to check some properties of selected DOM node.

Build Status

Simple tests usage

var DomChecker = require('@htmlacademy/dom-check');
var checker = new DomChecker(aDocument);

// returns true if document has `.some-node`
checker.node('.some-node').hasNode();

// returns true if `.div-node` is a div
checker.node('.div-node').isTag('div');

// returns true, if trimmed textContent equals `hello`
checker.node('.div-with-text').textIsEqual('hello');

Compare with etalon

Please, note that .reset() method is called each time before running your changes starting from version 1.3.39-2.

var DomChecker = require('@htmlacademy/dom-check');
var checker = new DomChecker(aDocument, {
  initialCode: {
    html: '...',   // some html code
    css: '...'     // some css code
  }
});

// returns true if document has `.some-node`
checker.changeEtalon(function() {
  // After running this callback
  //   `changeEtalon()` function puts all changes
  //   into etalon document, kept in iframe
  this.html(function() {   // select html mode and
    this.                  //   change it somehow
      find('Hello').       // Find first `Hello` string
      replace('Good-bye'); //   and replace it with `Good-bye`
  });
});

// Then you may check, for example:

// Attribute value
checker.node('.hello').hasSame('@width');

// Text content
checker.node('.hello').hasSame('text()');

// Several css-properties
checker.node('.hello').hasSame('padding-{top,left}');
// You may use 'color' or 'padding-*' format.
// It works, powered by minimatch

// Also, you may check a subtree!
checker.node('.hello').hasSameSubtree();

Find & replace methods

  • find() — finds single match to replace. Single argument may be string or regular expression
  • findAll() — finds every match in string to replace. Single argument may be string or regular expression. Regular expression must have a global flag set
  • findLine() — find line to replace. Argument is 1-based number.
  • findLines() — find lines range to replace. Both arguments are 1-based numbers.
  • replace() — replace selection with provided value.
  • remove() — alias for replace('').

Methods may be chained to select some fragment(s) in specified lines:

etalon.changeEtalon(function() {
  this.html(function() {
    this.
      findLines(1, 5).          // Select lines from 1 to 5
      findAll(/(foo|bar)/g).    // in those lines select all `foo` and `bar`
      replace('baz');           // and replace them with `baz`
  });
});

When find() or findAll() are used with regexp, replace() argument may be a function. Function will get a match data, and its result will be used as a value to replace selection.

1.3.77

4 years ago

1.3.76

4 years ago

1.3.75

4 years ago

1.3.73

4 years ago

1.3.74

4 years ago

1.3.72

4 years ago

1.3.71

4 years ago

1.3.70

4 years ago

1.3.69

5 years ago

1.3.68

5 years ago

1.3.67

5 years ago

1.3.66

5 years ago

1.3.65

5 years ago

1.3.64

5 years ago

1.3.62

5 years ago

1.3.60

5 years ago

1.3.59

5 years ago

1.3.58

5 years ago

1.3.57

5 years ago

1.3.56

5 years ago

1.3.55

5 years ago

1.3.54

5 years ago

1.3.53

5 years ago

1.3.52

5 years ago

1.3.51

5 years ago

1.3.50

5 years ago

1.3.49

5 years ago

1.3.48

5 years ago

1.3.47

5 years ago

1.3.46

5 years ago

1.3.45

5 years ago

1.3.44

5 years ago

1.3.43

5 years ago

1.3.42

5 years ago

1.3.41

6 years ago

1.3.40

6 years ago

1.3.39-10

6 years ago

1.3.39-8

6 years ago

1.3.39-7

6 years ago

1.3.39-6

6 years ago

1.3.39-5

6 years ago

1.3.39-4

6 years ago

1.3.39-3

6 years ago

1.3.39-2

6 years ago

1.3.39-1

6 years ago

1.3.39

6 years ago

1.3.38

6 years ago

1.3.37-5

6 years ago

1.3.37-4

6 years ago

1.3.37-3

6 years ago

1.3.37-2

6 years ago

1.3.37-1

6 years ago

1.3.37

6 years ago

1.3.36

6 years ago

1.3.35

6 years ago

1.3.34

6 years ago

1.3.33

6 years ago

1.3.32

6 years ago

1.3.31

6 years ago

1.3.30

6 years ago

1.3.29

6 years ago

1.3.28

6 years ago

1.3.27

6 years ago

1.3.26

6 years ago

1.3.25

6 years ago

1.3.24

6 years ago

1.3.23

6 years ago

1.3.22

6 years ago

1.3.21

6 years ago

1.3.20

6 years ago

1.3.19

6 years ago

1.3.18

7 years ago

1.3.17

7 years ago

1.3.15

7 years ago

1.3.14

7 years ago

1.3.13

7 years ago

1.3.12

7 years ago

1.3.11

7 years ago

1.3.10

7 years ago

1.3.9

7 years ago

1.3.8

7 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.0

7 years ago