Skip to content

Instantly share code, notes, and snippets.

@benjamingr benjamingr/index.js
Created Oct 22, 2018

Embed
What would you like to do?
const React = require('react');
const { expect } = require('chai');
const { shallow, configure } = require('enzyme');
const { createSandbox } = require('sinon');
require('react-dom'); // required by the enzyme adapter internally
const Adapter = require('enzyme-adapter-react-16');
configure({ adapter: new Adapter() });
var called = 0;
class Test extends React.Component {
doSomething() {
called++;
}
componentDidMount() {
this.intervalId = setInterval(this.doSomething, 1000);
console.log("Did Mount");
}
componentWillUnmount() {
debugger;
clearInterval(this.intervalId);
}
render() {
return React.createElement("div", null, null);
}
}
describe('<Test/>', () => {
const sandbox = createSandbox();
const ss = {};
before(() => {
ss.clock = sandbox.useFakeTimers({
loopLimit: 50,
});
});
afterEach(() => {
sandbox.resetHistory();
});
after(() => {
sandbox.restore();
});
it('should stop after unmount', () => {
shallow(React.createElement(Test, null, null))
.unmount();
console.log(ss.clock.timers);
debugger;
ss.clock.tick(10000);
console.log(ss.clock.timers);
expect(called).to.equal(1);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.