Skip to content

Commit

Permalink
Merge d5d3770 into 372c62f
Browse files Browse the repository at this point in the history
  • Loading branch information
marvinhagemeister committed Aug 19, 2019
2 parents 372c62f + d5d3770 commit 57d71b4
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion test/browser/spec.test.js
@@ -1,5 +1,5 @@
import { setupRerender } from 'preact/test-utils';
import { createElement as h, render, Component } from '../../src/index';
import { createElement as h, render, Component, options } from '../../src/index';
import { setupScratch, teardown } from '../_util/helpers';

/** @jsx h */
Expand Down Expand Up @@ -91,6 +91,10 @@ describe('Component spec', () => {
});

describe('forceUpdate', () => {
beforeEach(() => {
delete options._commit;
});

it('should force a rerender', () => {
let forceUpdate;
class ForceUpdateComponent extends Component {
Expand Down Expand Up @@ -133,5 +137,32 @@ describe('Component spec', () => {
expect(ForceUpdateComponent.prototype.forceUpdate).to.have.been.calledWith(callback);
expect(callback).to.have.been.called;
});

it('should queue commits', () => {
let spy = sinon.spy();
options._commit = spy;

class Child extends Component {
componentDidMount() {
this.forceUpdate();
}

render() {
return <div>child</div>;
}
}

class App extends Component {
render() {
return <Child />;
}
}

render(<App />, scratch);

expect(spy).to.be.calledTwice;
expect(spy.args[0][0]._component.constructor).to.equal(App);
expect(spy.args[1][0]._component.constructor).to.equal(Child);
});
});
});

0 comments on commit 57d71b4

Please sign in to comment.