MSD.js
and what we learned
import sinon from 'sinon'
// undefined' is not an object (evaluating 'modules[moduleId].call')// webpack configuration
resolve: {
alias: {
// it's necessary to import dist instead of sinon module
// exported by default and this hides this ugly fact from us
sinon: 'sinon/pkg/sinon.js'
}
}// some tested code
callAsync = (cb) => {
doStuff();
setTimeout(cb, 300);
};
// test
const fakedClocks = sinon.useFakeTimers();
const spy = sinon.spy();
callAsync(spy);
fakedClocks.tick(310);
expect(spy).to.have.been.calledOnce;
fakedClocks.restore();
it('shows table header', function () {
const headerContent = tableHeaderWrapper.find('.header-content');
expect(headerContent).to.be.present();
expect(headerContent).to.contain.text('Author name');
});
it('does not show filter popup by default', function () {
expect(tableHeaderWrapper.find('FilterContainer')).to.not.be.present();
});render, shallow, mount - what to use?
when you are interested only in html
Component displayName is important
const Loading = (props) => {
const msg = props.message || 'Loading...';
return (
<div className='loading__wrap'>
<div className='loading__inner'>
<img
src={loading}
className='loading__spinner'
alt='loading'
/>
<p>{msg}</p>
</div>
</div>
);
};
// won't work without it:
// expect(parentComponent.find('Loading')).to.be.present();
Loading.displayName = 'Loading';
export default Loading;