Skip to content

Commit 10c3bca

Browse files
Merge branch 'main' into vitest-sinon-browser-refs-events
2 parents d2e45fb + 88fcacb commit 10c3bca

File tree

12 files changed

+317
-265
lines changed

12 files changed

+317
-265
lines changed

test/_util/helpers.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createElement, options } from 'preact';
22
import { clearLog, getLog } from './logCall';
33
import { teardown as testUtilTeardown } from 'preact/test-utils';
4+
import { vi } from 'vitest';
45

56
/** @jsx createElement */
67

@@ -263,24 +264,25 @@ let attributesSpy, originalAttributesPropDescriptor;
263264

264265
export function spyOnElementAttributes() {
265266
const test = Object.getOwnPropertyDescriptor(Element.prototype, 'attributes');
267+
const getter = test?.get;
266268

267269
// 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+
// whether this prototype method is already a spy.
271+
if (!attributesSpy && !(getter && vi.isMockFunction(getter))) {
270272
if (!originalAttributesPropDescriptor) {
271273
originalAttributesPropDescriptor = Object.getOwnPropertyDescriptor(
272274
Element.prototype,
273275
'attributes'
274276
);
275277
}
276278

277-
attributesSpy = sinon.spy(Element.prototype, 'attributes', ['get']);
278-
} else if (test && test.get && test.get.isSinonProxy) {
279+
attributesSpy = vi.spyOn(Element.prototype, 'attributes', 'get');
280+
} else if (getter && vi.isMockFunction(getter)) {
279281
// Due to IE11 not resetting we will do this manually when it is a proxy.
280-
test.get.resetHistory();
282+
getter.mockClear();
281283
}
282284

283-
return attributesSpy || test;
285+
return attributesSpy || getter;
284286
}
285287

286288
function restoreElementAttributes() {

0 commit comments

Comments
 (0)