Test3.remove()']);
- expect(ref).to.have.been.calledOnce;
+ expect(ref).toHaveBeenCalledTimes(1);
});
});
diff --git a/test/browser/render.test.js b/test/browser/render.test.js
index 95444aa8ba..67d0c9bdd2 100644
--- a/test/browser/render.test.js
+++ b/test/browser/render.test.js
@@ -13,6 +13,7 @@ import {
} from '../_util/helpers';
import { clearLog, getLog, logCall } from '../_util/logCall';
import { useState } from 'preact/hooks';
+import { vi } from 'vitest';
/** @jsx createElement */
@@ -1236,19 +1237,17 @@ describe('render()', () => {
render(
');
- const sandbox = sinon.createSandbox();
+ const debounceSpy = vi.spyOn(options, 'debounceRendering');
try {
- sandbox.spy(options, 'debounceRendering');
-
comp.setState({ updates: 1 }, () => {
comp.setState({ updates: 2 });
});
rerender();
expect(scratch.innerHTML).to.equal('
');
- expect(options.debounceRendering).to.have.been.calledOnce;
+ expect(debounceSpy).toHaveBeenCalledTimes(1);
} finally {
- sandbox.restore();
+ debounceSpy.mockRestore();
}
});
@@ -1300,7 +1299,7 @@ describe('render()', () => {
'
'
);
- expect(attributesSpy.get).to.not.have.been.called;
+ expect(attributesSpy).not.toHaveBeenCalled();
render(
@@ -1312,7 +1311,7 @@ describe('render()', () => {
'
'
);
- expect(attributesSpy.get).to.not.have.been.called;
+ expect(attributesSpy).not.toHaveBeenCalled();
});
// #2926
diff --git a/test/browser/spec.test.js b/test/browser/spec.test.js
index 2511f803d5..34c2a2ffff 100644
--- a/test/browser/spec.test.js
+++ b/test/browser/spec.test.js
@@ -1,6 +1,7 @@
import { setupRerender } from 'preact/test-utils';
import { createElement, render, Component } from 'preact';
import { setupScratch, teardown } from '../_util/helpers';
+import { vi } from 'vitest';
/** @jsx createElement */
@@ -29,24 +30,26 @@ describe('Component spec', () => {
return
;
}
}
- sinon.spy(ForceUpdateComponent.prototype, 'componentWillUpdate');
- sinon.spy(ForceUpdateComponent.prototype, 'forceUpdate');
+ vi.spyOn(ForceUpdateComponent.prototype, 'componentWillUpdate');
+ vi.spyOn(ForceUpdateComponent.prototype, 'forceUpdate');
render(
, scratch);
- expect(ForceUpdateComponent.prototype.componentWillUpdate).not.to.have
- .been.called;
+ expect(
+ ForceUpdateComponent.prototype.componentWillUpdate
+ ).not.toHaveBeenCalled();
forceUpdate();
rerender();
- expect(ForceUpdateComponent.prototype.componentWillUpdate).to.have.been
- .called;
- expect(ForceUpdateComponent.prototype.forceUpdate).to.have.been.called;
+ expect(
+ ForceUpdateComponent.prototype.componentWillUpdate
+ ).toHaveBeenCalled();
+ expect(ForceUpdateComponent.prototype.forceUpdate).toHaveBeenCalled();
});
it('should add callback to renderCallbacks', () => {
/** @type {() => void} */
let forceUpdate;
- let callback = sinon.spy();
+ let callback = vi.fn();
class ForceUpdateComponent extends Component {
componentDidMount() {
forceUpdate = () => this.forceUpdate(callback);
@@ -55,17 +58,17 @@ describe('Component spec', () => {
return
;
}
}
- sinon.spy(ForceUpdateComponent.prototype, 'forceUpdate');
+ vi.spyOn(ForceUpdateComponent.prototype, 'forceUpdate');
render(
, scratch);
forceUpdate();
rerender();
- expect(ForceUpdateComponent.prototype.forceUpdate).to.have.been.called;
- expect(
- ForceUpdateComponent.prototype.forceUpdate
- ).to.have.been.calledWith(callback);
- expect(callback).to.have.been.called;
+ expect(ForceUpdateComponent.prototype.forceUpdate).toHaveBeenCalled();
+ expect(ForceUpdateComponent.prototype.forceUpdate).toHaveBeenCalledWith(
+ callback
+ );
+ expect(callback).toHaveBeenCalled();
});
});
});
diff --git a/test/browser/style.test.js b/test/browser/style.test.js
index e4baf0f99c..6192482a6a 100644
--- a/test/browser/style.test.js
+++ b/test/browser/style.test.js
@@ -1,5 +1,6 @@
import { createElement, render } from 'preact';
import { setupScratch, teardown, sortCss } from '../_util/helpers';
+import { vi } from 'vitest';
/** @jsx createElement */
@@ -24,9 +25,11 @@ describe('style attribute', () => {
it('should not call CSSStyleDeclaration.setProperty for style strings', () => {
render(
, scratch);
- sinon.stub(scratch.firstChild.style, 'setProperty');
+ vi.spyOn(scratch.firstChild.style, 'setProperty').mockImplementation(
+ () => {}
+ );
render(
, scratch);
- expect(scratch.firstChild.style.setProperty).to.not.be.called;
+ expect(scratch.firstChild.style.setProperty).not.toHaveBeenCalled();
});
it('should properly switch from string styles to object styles and back', () => {
@@ -194,12 +197,14 @@ describe('style attribute', () => {
it('should call CSSStyleDeclaration.setProperty for css vars', () => {
render(
, scratch);
- sinon.stub(scratch.firstChild.style, 'setProperty');
+ vi.spyOn(scratch.firstChild.style, 'setProperty').mockImplementation(
+ () => {}
+ );
render(
,
scratch
);
- expect(scratch.firstChild.style.setProperty).to.be.calledWith(
+ expect(scratch.firstChild.style.setProperty).toHaveBeenCalledWith(
'--foo',
'10px'
);
diff --git a/test/browser/svg.test.js b/test/browser/svg.test.js
index 1b19b50854..21c6bfc277 100644
--- a/test/browser/svg.test.js
+++ b/test/browser/svg.test.js
@@ -1,6 +1,7 @@
import { createElement, Component, render } from 'preact';
import { setupRerender } from 'preact/test-utils';
import { setupScratch, teardown, sortAttributes } from '../_util/helpers';
+import { vi } from 'vitest';
/** @jsx createElement */
@@ -195,25 +196,22 @@ describe('svg', () => {
);
render(
, scratch);
let root = scratch.firstChild;
- sinon.spy(root, 'removeAttribute');
+ vi.spyOn(root, 'removeAttribute');
render(
, scratch);
- expect(root.removeAttribute).to.have.been.calledOnce.and.calledWith(
- 'class'
- );
+ expect(root.removeAttribute).toHaveBeenCalledTimes(1);
+ expect(root.removeAttribute).toHaveBeenCalledWith('class');
- root.removeAttribute.restore();
+ root.removeAttribute.mockRestore();
render(
, scratch);
render(
, scratch);
root = scratch.firstChild;
- sinon.spy(root, 'setAttribute');
+ vi.spyOn(root, 'setAttribute');
render(
, scratch);
- expect(root.setAttribute).to.have.been.calledOnce.and.calledWith(
- 'class',
- 'foo_2'
- );
+ expect(root.setAttribute).toHaveBeenCalledTimes(1);
+ expect(root.setAttribute).toHaveBeenCalledWith('class', 'foo_2');
- root.setAttribute.restore();
+ root.setAttribute.mockRestore();
});
it('should still support class attribute', () => {