MCPcopy
hub / github.com/preactjs/preact / spyOnElementAttributes

Function spyOnElementAttributes

test/_util/helpers.jsx:264–284  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

262let attributesSpy, originalAttributesPropDescriptor;
263
264export function spyOnElementAttributes() {
265 const test = Object.getOwnPropertyDescriptor(Element.prototype, 'attributes');
266
267 // IE11 doesn't correctly restore the prototype methods so we have to check
268 // whether this prototype method is already a sinon spy.
269 if (!attributesSpy && !(test && test.get && test.get.isSinonProxy)) {
270 if (!originalAttributesPropDescriptor) {
271 originalAttributesPropDescriptor = Object.getOwnPropertyDescriptor(
272 Element.prototype,
273 'attributes'
274 );
275 }
276
277 attributesSpy = sinon.spy(Element.prototype, 'attributes', ['get']);
278 } else if (test && test.get && test.get.isSinonProxy) {
279 // Due to IE11 not resetting we will do this manually when it is a proxy.
280 test.get.resetHistory();
281 }
282
283 return attributesSpy || test;
284}
285
286function restoreElementAttributes() {
287 if (originalAttributesPropDescriptor) {

Callers 2

hydrate.test.jsxFile · 0.90
render.test.jsxFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…