mirror of
https://github.com/reduxjs/redux-devtools.git
synced 2024-11-25 19:13:56 +03:00
initial test for the counter and todomvc examples
This commit is contained in:
parent
a297a3606a
commit
37c6ab7f69
|
@ -4,7 +4,10 @@
|
|||
"description": "Counter example for redux",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
"start": "node server.js",
|
||||
"test": "NODE_ENV=test mocha --compilers js:babel/register --recursive",
|
||||
"test:watch": "NODE_ENV=test mocha --compilers js:babel/register --recursive --watch",
|
||||
"test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -22,11 +25,15 @@
|
|||
"redux-thunk": "^0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "^5.5.8",
|
||||
"babel-core": "^5.6.18",
|
||||
"babel-loader": "^5.1.4",
|
||||
"node-libs-browser": "^0.5.2",
|
||||
"react-hot-loader": "^1.2.7",
|
||||
"webpack": "^1.9.11",
|
||||
"webpack-dev-server": "^1.9.0"
|
||||
"webpack-dev-server": "^1.9.0",
|
||||
"expect": "^1.6.0",
|
||||
"isparta": "^3.0.3",
|
||||
"mocha": "^2.2.5"
|
||||
}
|
||||
}
|
||||
|
|
18
examples/counter/test/actions.spec.js
Normal file
18
examples/counter/test/actions.spec.js
Normal file
|
@ -0,0 +1,18 @@
|
|||
import expect from 'expect';
|
||||
import { increment, decrement } from '../actions/CounterActions';
|
||||
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
||||
|
||||
|
||||
describe('actions', () => {
|
||||
it('returns increment counter action type', () => {
|
||||
const { type } = increment();
|
||||
|
||||
expect(type).toEqual(INCREMENT_COUNTER);
|
||||
});
|
||||
|
||||
it('returns decrement counter action type', () => {
|
||||
const { type } = decrement();
|
||||
|
||||
expect(type).toEqual(DECREMENT_COUNTER);
|
||||
});
|
||||
});
|
40
examples/counter/test/reducers.spec.js
Normal file
40
examples/counter/test/reducers.spec.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
import expect from 'expect';
|
||||
import counter from '../reducers/counter';
|
||||
import { INCREMENT_COUNTER, DECREMENT_COUNTER } from '../constants/ActionTypes';
|
||||
|
||||
describe('reducers', () => {
|
||||
|
||||
describe('counter', () => {
|
||||
|
||||
it('increments the counter', () => {
|
||||
const action = {
|
||||
type: INCREMENT_COUNTER
|
||||
};
|
||||
|
||||
const state = counter(0, action);
|
||||
|
||||
expect(state).toEqual(1);
|
||||
});
|
||||
|
||||
it('decrements the counter', () => {
|
||||
const action = {
|
||||
type: DECREMENT_COUNTER
|
||||
};
|
||||
|
||||
const state = counter(0, action);
|
||||
|
||||
expect(state).toEqual(-1);
|
||||
});
|
||||
|
||||
it('returns the state by default', () => {
|
||||
const action = {
|
||||
type: null
|
||||
};
|
||||
|
||||
const state = counter(2, action);
|
||||
|
||||
expect(state).toEqual(2);
|
||||
});
|
||||
|
||||
});
|
||||
});
|
|
@ -4,7 +4,10 @@
|
|||
"description": "TodoMVC example for redux",
|
||||
"main": "server.js",
|
||||
"scripts": {
|
||||
"start": "node server.js"
|
||||
"start": "node server.js",
|
||||
"test": "NODE_ENV=test mocha --compilers js:babel/register --recursive",
|
||||
"test:watch": "NODE_ENV=test mocha --compilers js:babel/register --recursive --watch",
|
||||
"test:cov": "babel-node ./node_modules/.bin/isparta cover ./node_modules/.bin/_mocha -- --recursive"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
@ -34,6 +37,7 @@
|
|||
"redux": "^1.0.0-rc"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel": "^5.5.8",
|
||||
"babel-core": "^5.6.18",
|
||||
"babel-loader": "^5.1.4",
|
||||
"node-libs-browser": "^0.5.2",
|
||||
|
@ -42,6 +46,9 @@
|
|||
"style-loader": "^0.12.3",
|
||||
"todomvc-app-css": "^2.0.1",
|
||||
"webpack": "^1.9.11",
|
||||
"webpack-dev-server": "^1.9.0"
|
||||
"webpack-dev-server": "^1.9.0",
|
||||
"expect": "^1.6.0",
|
||||
"isparta": "^3.0.3",
|
||||
"mocha": "^2.2.5"
|
||||
}
|
||||
}
|
||||
|
|
52
examples/todomvc/test/actions.spec.js
Normal file
52
examples/todomvc/test/actions.spec.js
Normal file
|
@ -0,0 +1,52 @@
|
|||
import expect from 'expect';
|
||||
import { addTodo, deleteTodo, editTodo, markTodo, markAll, clearMarked } from '../actions/TodoActions';
|
||||
import * as types from '../constants/ActionTypes';
|
||||
|
||||
|
||||
describe('actions', () => {
|
||||
it('returns add todo action type and text', () => {
|
||||
const todoText = 'My first TODO';
|
||||
const { type, text } = addTodo(todoText);
|
||||
|
||||
expect(type).toEqual(types.ADD_TODO);
|
||||
expect(text).toEqual(todoText);
|
||||
});
|
||||
|
||||
it('returns delete todo action type and id of deleted todo', () => {
|
||||
const todoId = 1;
|
||||
const { type, id } = deleteTodo(todoId);
|
||||
|
||||
expect(type).toEqual(types.DELETE_TODO);
|
||||
expect(id).toEqual(todoId);
|
||||
});
|
||||
|
||||
it('returns edit todo action type, its id and new text', () => {
|
||||
const todoId = 1;
|
||||
const editedTodo = 'My edited TODO';
|
||||
const { type, id, text } = editTodo(todoId, editedTodo);
|
||||
|
||||
expect(type).toEqual(types.EDIT_TODO);
|
||||
expect(id).toEqual(todoId);
|
||||
expect(text).toEqual(editedTodo);
|
||||
});
|
||||
|
||||
it('returns mark todo action type and the id', () => {
|
||||
const todoId = 1;
|
||||
const { type, id } = markTodo(todoId);
|
||||
|
||||
expect(type).toEqual(types.MARK_TODO);
|
||||
expect(id).toEqual(todoId);
|
||||
});
|
||||
|
||||
it('returns mark all action type', () => {
|
||||
const { type } = markAll();
|
||||
|
||||
expect(type).toEqual(types.MARK_ALL);
|
||||
});
|
||||
|
||||
it('returns clear marked action type', () => {
|
||||
const { type } = clearMarked();
|
||||
|
||||
expect(type).toEqual(types.CLEAR_MARKED);
|
||||
});
|
||||
});
|
132
examples/todomvc/test/reducers.spec.js
Normal file
132
examples/todomvc/test/reducers.spec.js
Normal file
|
@ -0,0 +1,132 @@
|
|||
import expect from 'expect';
|
||||
import todos from '../reducers/todos';
|
||||
import { ADD_TODO, DELETE_TODO, EDIT_TODO, MARK_TODO, MARK_ALL, CLEAR_MARKED } from '../constants/ActionTypes';
|
||||
|
||||
describe('reducers', () => {
|
||||
|
||||
describe('todos', () => {
|
||||
|
||||
let initialState;
|
||||
|
||||
beforeEach(() => {
|
||||
initialState = [{
|
||||
text: 'Use Redux',
|
||||
marked: false,
|
||||
id: 0
|
||||
}];
|
||||
});
|
||||
|
||||
it('adds a new todo', () => {
|
||||
const todoText = 'My TODO';
|
||||
const action = {
|
||||
type: ADD_TODO,
|
||||
text: todoText
|
||||
};
|
||||
|
||||
const state = todos(initialState, action);
|
||||
|
||||
expect(state.length).toEqual(2);
|
||||
expect(state[0].text).toEqual(todoText);
|
||||
expect(state[0].marked).toEqual(false);
|
||||
expect(state[0].id).toEqual(state[1].id + 1);
|
||||
});
|
||||
|
||||
it('deletes todo', () => {
|
||||
const todoId = 0;
|
||||
const action = {
|
||||
type: DELETE_TODO,
|
||||
id: todoId
|
||||
};
|
||||
|
||||
const state = todos(initialState, action);
|
||||
|
||||
expect(state.length).toEqual(0);
|
||||
});
|
||||
|
||||
it('edits todo', () => {
|
||||
const todoId = 0;
|
||||
const todoText = 'My TODO';
|
||||
const action = {
|
||||
type: EDIT_TODO,
|
||||
id: todoId,
|
||||
text: todoText
|
||||
};
|
||||
|
||||
const state = todos(initialState, action);
|
||||
|
||||
expect(state.length).toEqual(1);
|
||||
expect(state[0].text).toEqual(todoText);
|
||||
expect(state[0].marked).toEqual(false);
|
||||
});
|
||||
|
||||
it('marks todo', () => {
|
||||
const todoId = 0;
|
||||
const action = {
|
||||
type: MARK_TODO,
|
||||
id: todoId
|
||||
};
|
||||
|
||||
const state = todos(initialState, action);
|
||||
|
||||
expect(state.length).toEqual(1);
|
||||
expect(state[0].marked).toEqual(true);
|
||||
});
|
||||
|
||||
it('marks all todos', () => {
|
||||
const newState = [{
|
||||
text: 'Use Redux',
|
||||
marked: false,
|
||||
id: 1
|
||||
}, {
|
||||
text: 'Write tests',
|
||||
marked: false,
|
||||
id: 0
|
||||
}];
|
||||
|
||||
const action = {
|
||||
type: MARK_ALL
|
||||
};
|
||||
|
||||
const state = todos(newState, action);
|
||||
|
||||
expect(state.length).toEqual(2);
|
||||
expect(state[0].marked).toEqual(true);
|
||||
expect(state[1].marked).toEqual(true);
|
||||
});
|
||||
|
||||
it('clears all marked todos', () => {
|
||||
const newState = [{
|
||||
text: 'Use Redux-DevTools',
|
||||
marked: true,
|
||||
id: 2
|
||||
}, {
|
||||
text: 'Use Redux',
|
||||
marked: true,
|
||||
id: 1
|
||||
}, {
|
||||
text: 'Write tests',
|
||||
marked: false,
|
||||
id: 0
|
||||
}];
|
||||
|
||||
const action = {
|
||||
type: CLEAR_MARKED
|
||||
};
|
||||
|
||||
const state = todos(newState, action);
|
||||
|
||||
expect(state.length).toEqual(1);
|
||||
expect(state[0].marked).toEqual(false);
|
||||
});
|
||||
|
||||
it('returns the state by default', () => {
|
||||
const action = {
|
||||
type: null
|
||||
};
|
||||
|
||||
const state = todos(initialState, action);
|
||||
|
||||
expect(state).toEqual(initialState);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user