Repository: angular/angular.js
File: test/jqLiteSpec.js (JavaScript)

Code before:
      });

      it('should allow to restore legacy insecure behavior', function() {
        // jQuery doesn't have this API.
        if (!_jqLiteMode) return;

        // eslint-disable-next-line new-cap
        angular.UNSAFE_restoreLegacyJqLiteXHTMLReplacement();

        var elem = jqLite('<div/><span/>');
        expect(elem.length).toBe(2);
        expect(elem[0].nodeName.toLowerCase()).toBe('div');
        expect(elem[1].nodeName.toLowerCase()).toBe('span');
      });
    });
  });

  describe('_data', function() {
    it('should provide access to the events present on the element', function() {
      var element = jqLite('<i>foo</i>');
      expect(angular.element._data(element[0]).events).toBeUndefined();

      element.on('click', function() { });
      expect(angular.element._data(element[0]).events.click).toBeDefined();
    });
  });

  describe('inheritedData', function() {

    it('should retrieve data attached to the current element', function() {
      var element = jqLite('<i>foo</i>');
      element.data('myData', 'abc');
      expect(element.inheritedData('myData')).toBe('abc');
      dealoc(element);
    });


    it('should walk up the dom to find data', function() {
      var element = jqLite('<ul><li><p><b>deep deep</b><p></li></ul>');
      var deepChild = jqLite(element[0].getElementsByTagName('b')[0]);
      element.data('myData', 'abc');
      expect(deepChild.inheritedData('myData')).toBe('abc');
      dealoc(element);
    });


    it('should return undefined when no data was found', function() {
      var element = jqLite('<ul><li><p><b>deep deep</b><p></li></ul>');
      var deepChild = jqLite(element[0].getElementsByTagName('b')[0]);
      expect(deepChild.inheritedData('myData')).toBeFalsy();
      dealoc(element);

Review comment (bug):
Is it possible to get a false-positive (i.e. an anti-flake)?
If the timeout completes before the async changes have occurred, it is possible that the test could have failed if the timeout were longer.

I guess that the `onerror` handler is always called async?

Could we avoid relying upon the timeout being long enough. Perhaps create an additional "real" error that will call a different `onerror` handler? Then assume that if this second handler is called but  the `xss` one is not called then we are good... Then we could make the `it` async and only call `done()` once the second real error handler has been called.

Code after:
        // decimal parameters for the assertions to be correct.
        forEach([
          '<img alt="<x" title="/><img src=url404 onerror=xss(0)>">',
          '<img alt="\n<x" title="/>\n<img src=url404 onerror=xss(1)>">',
          '<style><style/><img src=url404 onerror=xss(2)>',
          '<xmp><xmp/><img src=url404 onerror=xss(3)>',
          '<title><title /><img src=url404 onerror=xss(4)>',
          '<iframe><iframe/><img src=url404 onerror=xss(5)>',
          '<noframes><noframes/><img src=url404 onerror=xss(6)>',
          '<noscript><noscript/><img src=url404 onerror=xss(7)>',
          '<foo" alt="" title="/><img src=url404 onerror=xss(8)>">',
          '<img alt="<x" title="" src="/><img src=url404 onerror=xss(9)>">',
          '<noscript/><img src=url404 onerror=xss(10)>',
          '<noembed><noembed/><img src=url404 onerror=xss(11)>',

          '<option><style></option></select><img src=url404 onerror=xss(12)></style>'
        ], function(htmlString, index) {
          var element = jqLite('<div></div>');

          container.append(element);
          element.append(jqLite(htmlString));

          window.setTimeout(function() {
            expect(window.xss).not.toHaveBeenCalledWith(index);
            donePartial();
          }, 1000);
        });
      });

      it('should allow to restore legacy insecure behavior', function() {
        // jQuery doesn't have this API.
        if (!_jqLiteMode) return;

        // eslint-disable-next-line new-cap
        angular.UNSAFE_restoreLegacyJqLiteXHTMLReplacement();

        var elem = jqLite('<div/><span/>');
        expect(elem.length).toBe(2);
        expect(elem[0].nodeName.toLowerCase()).toBe('div');
        expect(elem[1].nodeName.toLowerCase()).toBe('span');
      });
    });
  });

  describe('_data', function() {
    it('should provide access to the events present on the element', function() {
      var element = jqLite('<i>foo</i>');
      expect(angular.element._data(element[0]).events).toBeUndefined();

      element.on('click', function() { });
      expect(angular.element._data(element[0]).events.click).toBeDefined();