Created
October 22, 2018 14:26
-
-
Save benjamingr/3bd6f444d78c69b8931aafe8f159183e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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