redux-devtools/packages/redux-devtools-trace-monitor/test/StackTraceTab.spec.js
2018-12-13 03:38:25 +02:00

50 lines
1.3 KiB
JavaScript

import React from 'react';
import { configure, mount } from 'enzyme';
import toJson from 'enzyme-to-json';
import StackTraceTab from '../src/StackTraceTab';
import Adapter from 'enzyme-adapter-react-15';
configure({ adapter: new Adapter() });
function genAsyncSnapshot(component, done) {
setTimeout(() => {
component.update();
expect(toJson(component)).toMatchSnapshot();
done();
});
}
const actions = {
0: { type: 'PERFORM_ACTION', action: { type: '@@INIT' } },
1: { type: 'PERFORM_ACTION', action: { type: 'INCREMENT_COUNTER' } },
2: {
type: 'PERFORM_ACTION', action: { type: 'INCREMENT_COUNTER' },
stack: 'Error\n at fn1 (app.js:72:24)\n at fn2 (app.js:84:31)'
}
};
describe('StackTraceTab component', () => {
it('should render with no props', (done) => {
const component = mount(<StackTraceTab />);
genAsyncSnapshot(component, done);
});
it('should render with props, but without stack', (done) => {
const component = mount(
<StackTraceTab
actions={actions} action={actions[0].action}
/>
);
genAsyncSnapshot(component, done);
});
it('should render with trace stack', (done) => {
const component = mount(
<StackTraceTab
actions={actions} action={actions[2].action}
/>
);
genAsyncSnapshot(component, done);
});
});