Skip to content

Commit

Permalink
Improve coverage, pt. 1
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewiggins committed Oct 27, 2023
1 parent cff2df5 commit 3534a4f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
5 changes: 0 additions & 5 deletions compat/src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@ export function shallowDiffers(a, b) {
return false;
}

export function removeNode(node) {
let parentNode = node.parentNode;
if (parentNode) parentNode.removeChild(node);
}

/**
* Check if two values are the same value
* @param {*} x
Expand Down
11 changes: 10 additions & 1 deletion jsx-runtime/test/browser/jsx-runtime.test.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
import { Component, createElement, createRef } from 'preact';
import { Component, createElement, createRef, options } from 'preact';
import { jsx, jsxs, jsxDEV, Fragment } from 'preact/jsx-runtime';
import { setupScratch, teardown } from '../../../test/_util/helpers';

describe('Babel jsx/jsxDEV', () => {
let scratch;
let prevVNodeOption;

beforeEach(() => {
scratch = setupScratch();
prevVNodeOption = options.vnode;
});

afterEach(() => {
options.vnode = prevVNodeOption;
teardown(scratch);
});

Expand Down Expand Up @@ -91,4 +94,10 @@ describe('Babel jsx/jsxDEV', () => {
expect(vnode.props).to.deep.equal({});
expect(vnode.ref).to.equal(ref);
});

it('should call options.vnode with the vnode', () => {
options.vnode = sinon.spy();
const vnode = jsx('div', { class: 'foo' }, 'key');
expect(options.vnode).to.have.been.calledWith(vnode);
});
});
16 changes: 14 additions & 2 deletions test-utils/test/shared/act.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ describe('act', () => {
act(() => {
tryRenderBroken();
});
}
};

describe('synchronously', () => {
it('should rethrow the exception', () => {
Expand All @@ -407,7 +407,7 @@ describe('act', () => {
renderWorking();
expect(scratch.textContent).to.equal('1');
});

it('should not affect effects in future renders', () => {
tryRenderBroken();
renderWorking();
Expand All @@ -432,6 +432,18 @@ describe('act', () => {
expect(err.message).to.equal('BrokenWidget is broken');
});

it('should rethrow the exception in nested act calls', async () => {
let err;
try {
await act(async () => {
await renderBrokenAsync();
});
} catch (e) {
err = e;
}
expect(err.message).to.equal('BrokenWidget is broken');
});

it('should not affect state updates in future renders', async () => {
try {
await renderBrokenAsync();
Expand Down

0 comments on commit 3534a4f

Please sign in to comment.