|
1 | 1 | import { createElement, options } from 'preact'; |
2 | 2 | import { clearLog, getLog } from './logCall'; |
3 | 3 | import { teardown as testUtilTeardown } from 'preact/test-utils'; |
| 4 | +import { vi } from 'vitest'; |
4 | 5 |
|
5 | 6 | /** @jsx createElement */ |
6 | 7 |
|
@@ -263,24 +264,25 @@ let attributesSpy, originalAttributesPropDescriptor; |
263 | 264 |
|
264 | 265 | export function spyOnElementAttributes() { |
265 | 266 | const test = Object.getOwnPropertyDescriptor(Element.prototype, 'attributes'); |
| 267 | + const getter = test?.get; |
266 | 268 |
|
267 | 269 | // 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))) { |
270 | 272 | if (!originalAttributesPropDescriptor) { |
271 | 273 | originalAttributesPropDescriptor = Object.getOwnPropertyDescriptor( |
272 | 274 | Element.prototype, |
273 | 275 | 'attributes' |
274 | 276 | ); |
275 | 277 | } |
276 | 278 |
|
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)) { |
279 | 281 | // Due to IE11 not resetting we will do this manually when it is a proxy. |
280 | | - test.get.resetHistory(); |
| 282 | + getter.mockClear(); |
281 | 283 | } |
282 | 284 |
|
283 | | - return attributesSpy || test; |
| 285 | + return attributesSpy || getter; |
284 | 286 | } |
285 | 287 |
|
286 | 288 | function restoreElementAttributes() { |
|
0 commit comments