Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions debug/test/browser/component-stack-2.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createElement, render, Component } from 'preact';
import 'preact/debug';
import { setupScratch, teardown } from '../../../test/_util/helpers';
import { vi } from 'vitest';

/** @jsx createElement */

Expand All @@ -19,13 +20,13 @@ describe('component stack', () => {

errors = [];
warnings = [];
sinon.stub(console, 'error').callsFake(e => errors.push(e));
sinon.stub(console, 'warn').callsFake(w => warnings.push(w));
vi.spyOn(console, 'error').mockImplementation(e => errors.push(e));
vi.spyOn(console, 'warn').mockImplementation(w => warnings.push(w));
});

afterEach(() => {
console.error.restore();
console.warn.restore();
console.error.mockRestore();
console.warn.mockRestore();
teardown(scratch);
});

Expand Down
11 changes: 6 additions & 5 deletions debug/test/browser/debug-compat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import * as PropTypes from 'prop-types';
// eslint-disable-next-line no-duplicate-imports
import { resetPropWarnings } from 'preact/debug';
import { forwardRef, createPortal } from 'preact/compat';
import { vi } from 'vitest';

const h = createElement;
/** @jsx createElement */
Expand All @@ -21,17 +22,17 @@ describe('debug compat', () => {
errors = [];
warnings = [];
scratch = setupScratch();
sinon.stub(console, 'error').callsFake(e => errors.push(e));
sinon.stub(console, 'warn').callsFake(w => warnings.push(w));
vi.spyOn(console, 'error').mockImplementation(e => errors.push(e));
vi.spyOn(console, 'warn').mockImplementation(w => warnings.push(w));

root = document.createElement('div');
document.body.appendChild(root);
});

afterEach(() => {
/** @type {*} */
console.error.restore();
console.warn.restore();
console.error.mockRestore();
console.warn.mockRestore();
teardown(scratch);

document.body.removeChild(root);
Expand Down Expand Up @@ -73,7 +74,7 @@ describe('debug compat', () => {

render(<Foo ref={ref} text="123" />, scratch);

expect(console.error).not.been.called;
expect(console.error).not.toHaveBeenCalled();

expect(ref.current).to.not.be.undefined;
});
Expand Down
9 changes: 5 additions & 4 deletions debug/test/browser/debug-hooks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useState, useEffect } from 'preact/hooks';
import 'preact/debug';
import { act } from 'preact/test-utils';
import { setupScratch, teardown } from '../../../test/_util/helpers';
import { vi } from 'vitest';

/** @jsx createElement */

Expand All @@ -15,13 +16,13 @@ describe('debug with hooks', () => {
errors = [];
warnings = [];
scratch = setupScratch();
sinon.stub(console, 'error').callsFake(e => errors.push(e));
sinon.stub(console, 'warn').callsFake(w => warnings.push(w));
vi.spyOn(console, 'error').mockImplementation(e => errors.push(e));
vi.spyOn(console, 'warn').mockImplementation(w => warnings.push(w));
});

afterEach(() => {
console.error.restore();
console.warn.restore();
console.error.mockRestore();
console.warn.mockRestore();
teardown(scratch);
});

Expand Down
19 changes: 10 additions & 9 deletions debug/test/browser/debug-suspense.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
teardown,
serializeHtml
} from '../../../test/_util/helpers';
import { vi } from 'vitest';

/** @jsx createElement */

Expand All @@ -21,13 +22,13 @@ describe('debug with suspense', () => {
warnings = [];
scratch = setupScratch();
rerender = setupRerender();
sinon.stub(console, 'error').callsFake(e => errors.push(e));
sinon.stub(console, 'warn').callsFake(w => warnings.push(w));
vi.spyOn(console, 'error').mockImplementation(e => errors.push(e));
vi.spyOn(console, 'warn').mockImplementation(w => warnings.push(w));
});

afterEach(() => {
console.error.restore();
console.warn.restore();
console.error.mockRestore();
console.warn.mockRestore();
teardown(scratch);
});

Expand Down Expand Up @@ -74,7 +75,7 @@ describe('debug with suspense', () => {
render(suspense, scratch);
rerender(); // render fallback

expect(console.error).to.not.be.called;
expect(console.error).not.toHaveBeenCalled();
expect(serializeHtml(scratch)).to.equal('<div>fallback...</div>');

return loader.then(() => {
Expand Down Expand Up @@ -106,7 +107,7 @@ describe('debug with suspense', () => {

return loader.then(() => {
rerender();
expect(console.warn).to.be.calledTwice;
expect(console.warn).toHaveBeenCalledTimes(2);
expect(warnings[1].includes('MyLazyLoaded')).to.equal(true);
expect(serializeHtml(scratch)).to.equal('<div>Hi there</div>');
});
Expand All @@ -132,7 +133,7 @@ describe('debug with suspense', () => {

return loader.then(() => {
rerender();
expect(console.warn).to.be.calledTwice;
expect(console.warn).toHaveBeenCalledTimes(2);
expect(warnings[1].includes('HelloLazy')).to.equal(true);
expect(serializeHtml(scratch)).to.equal('<div>Hi there</div>');
});
Expand Down Expand Up @@ -160,7 +161,7 @@ describe('debug with suspense', () => {
}

// Called once on initial render, and again when promise rejects
expect(console.warn).to.be.calledTwice;
expect(console.warn).toHaveBeenCalledTimes(2);
});
});

Expand All @@ -181,7 +182,7 @@ describe('debug with suspense', () => {
error = e;
}

expect(console.warn).to.be.calledOnce;
expect(console.warn).toHaveBeenCalledOnce();
expect(error).not.to.be.undefined;
expect(error.message).to.eql('Hello');
});
Expand Down
9 changes: 5 additions & 4 deletions debug/test/browser/debug.options.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { useState } from 'preact/hooks';
import { setupRerender } from 'preact/test-utils';
import 'preact/debug';
import { setupScratch, teardown } from '../../../test/_util/helpers';
import { vi } from 'vitest';

/** @jsx createElement */

Expand All @@ -25,7 +26,7 @@ describe('debug options', () => {
/** @type {(count: number) => void} */
let setCount;

/** @type {import('sinon').SinonFakeTimers | undefined} */
/** @type {import('vitest').VitestUtils | undefined} */
let clock;

beforeEach(() => {
Expand All @@ -42,7 +43,7 @@ describe('debug options', () => {

afterEach(() => {
teardown(scratch);
if (clock) clock.restore();
if (clock) vi.useRealTimers();
});

class ClassApp extends Component {
Expand Down Expand Up @@ -123,7 +124,7 @@ describe('debug options', () => {
}
}

clock = sinon.useFakeTimers();
clock = vi.useFakeTimers();

render(<ErrorApp />, scratch);
rerender();
Expand All @@ -132,6 +133,6 @@ describe('debug options', () => {

// we expect to throw after setTimeout to trigger a window.onerror
// this is to ensure react compat (i.e. with next.js' dev overlay)
expect(() => clock.tick(0)).to.throw(e);
expect(() => clock.advanceTimersByTime(0)).to.throw(e);
});
});
Loading
Loading