feature: add sample tests
This commit is contained in:
parent
e55ddacf2e
commit
4674909ecb
|
@ -0,0 +1,28 @@
|
||||||
|
import configureStore from 'redux-mock-store';
|
||||||
|
|
||||||
|
import { ADD_TODO } from '../../app/constants/actions';
|
||||||
|
|
||||||
|
import { addTodo } from '../../app/actions/add-todo';
|
||||||
|
|
||||||
|
const store = configureStore()();
|
||||||
|
|
||||||
|
describe('Todo Actions', () => {
|
||||||
|
beforeEach(() => store.clearActions());
|
||||||
|
|
||||||
|
test('should create an action to add a new todo', () => {
|
||||||
|
const text = 'Hello World!';
|
||||||
|
|
||||||
|
store.dispatch(addTodo(text));
|
||||||
|
expect(store.getActions()[0]).toEqual(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: ADD_TODO,
|
||||||
|
payload: {
|
||||||
|
text,
|
||||||
|
id: expect.any(String),
|
||||||
|
editing: false,
|
||||||
|
createdAt: expect.any(Number),
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,16 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { shallow } from 'enzyme';
|
||||||
|
import toJson from 'enzyme-to-json';
|
||||||
|
|
||||||
|
import { SidebarComponent } from '../../app/components/sidebar/index';
|
||||||
|
|
||||||
|
describe('<Sidebar />', () => {
|
||||||
|
describe('render()', () => {
|
||||||
|
test('should render correctly', () => {
|
||||||
|
const wrapper = shallow(<SidebarComponent />);
|
||||||
|
const component = wrapper.dive();
|
||||||
|
|
||||||
|
expect(toJson(component)).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,69 @@
|
||||||
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`<Sidebar /> render() should render correctly 1`] = `
|
||||||
|
<StyledComponent
|
||||||
|
forwardedClass={
|
||||||
|
Object {
|
||||||
|
"$$typeof": Symbol(react.forward_ref),
|
||||||
|
"attrs": Array [],
|
||||||
|
"componentStyle": ComponentStyle {
|
||||||
|
"componentId": "sc-bdVaJa",
|
||||||
|
"isStatic": true,
|
||||||
|
"rules": Array [
|
||||||
|
"
|
||||||
|
",
|
||||||
|
"
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
width: 200px;
|
||||||
|
position: absolute;
|
||||||
|
left: 0;
|
||||||
|
top: 0;
|
||||||
|
height: 100vh;
|
||||||
|
background: #ccc;
|
||||||
|
",
|
||||||
|
"
|
||||||
|
",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
"displayName": "styled.div",
|
||||||
|
"render": [Function],
|
||||||
|
"styledComponentId": "sc-bdVaJa",
|
||||||
|
"target": "div",
|
||||||
|
"toString": [Function],
|
||||||
|
"warnTooManyClasses": [Function],
|
||||||
|
"withComponent": [Function],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
forwardedRef={null}
|
||||||
|
>
|
||||||
|
<Link
|
||||||
|
key="/"
|
||||||
|
replace={false}
|
||||||
|
to="/"
|
||||||
|
>
|
||||||
|
Dashboard
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
key="/send"
|
||||||
|
replace={false}
|
||||||
|
to="/send"
|
||||||
|
>
|
||||||
|
Send
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
key="/receive"
|
||||||
|
replace={false}
|
||||||
|
to="/receive"
|
||||||
|
>
|
||||||
|
Receive
|
||||||
|
</Link>
|
||||||
|
<Link
|
||||||
|
key="/settings"
|
||||||
|
replace={false}
|
||||||
|
to="/settings"
|
||||||
|
>
|
||||||
|
Settings
|
||||||
|
</Link>
|
||||||
|
</StyledComponent>
|
||||||
|
`;
|
|
@ -0,0 +1,26 @@
|
||||||
|
import todoReducer from '../../app/reducers/todo';
|
||||||
|
import { ADD_TODO } from '../../app/constants/actions';
|
||||||
|
|
||||||
|
describe('Todo Reducer', () => {
|
||||||
|
test('should return the valid initial state', () => {
|
||||||
|
const action = { type: 'UNKNOWN_ACTION' };
|
||||||
|
const initialState = [];
|
||||||
|
|
||||||
|
expect(todoReducer(undefined, action)).toEqual(initialState);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should add a new todo', () => {
|
||||||
|
const action = {
|
||||||
|
type: ADD_TODO,
|
||||||
|
payload: {
|
||||||
|
id: 'abc123',
|
||||||
|
text: 'Hello World!',
|
||||||
|
editing: false,
|
||||||
|
createdAt: new Date().getTime(),
|
||||||
|
},
|
||||||
|
};
|
||||||
|
const expectedState = [action.payload];
|
||||||
|
|
||||||
|
expect(todoReducer(undefined, action)).toEqual(expectedState);
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue