@cypress/unique-selector 2.1.0 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/lib/getTag.js +24 -1
  2. package/package.json +1 -1
package/lib/getTag.js CHANGED
@@ -4,6 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getTag = getTag;
7
+ function isString(value) {
8
+ return typeof value === 'string';
9
+ }
10
+
7
11
  /**
8
12
  * Returns the Tag of the element
9
13
  * @param { Object } element
@@ -11,7 +15,26 @@ exports.getTag = getTag;
11
15
  * @return { String }
12
16
  */
13
17
  function getTag(el, filter) {
14
- var tagName = el.tagName.toLowerCase().replace(/:/g, '\\:');
18
+ var tagName = el.tagName;
19
+
20
+ // If the tagName attribute has been overridden, we should
21
+ // check the nodeName property instead. If the nodeName property
22
+ // is also not a string, we should return null and ignore tagName
23
+ // for selector generation.
24
+ //
25
+ // This can happen when a <form> element contains an <input>
26
+ // with an id of `tagName`. In this case, the form element's
27
+ // tagName property is a reference to the input element, not
28
+ // a string.
29
+ if (!isString(tagName)) {
30
+ tagName = el.nodeName;
31
+
32
+ if (!isString(tagName)) {
33
+ return null;
34
+ }
35
+ }
36
+
37
+ tagName = tagName.toLowerCase().replace(/:/g, '\\:');
15
38
 
16
39
  if (filter && !filter('tag', 'tag', tagName)) {
17
40
  return null;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cypress/unique-selector",
3
- "version": "2.1.0",
3
+ "version": "2.1.1",
4
4
  "description": "Given a DOM node, return a unique CSS selector matching only that element",
5
5
  "main": "./lib/index.js",
6
6
  "jsnext:main": "./src/index.js",