Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add specs to 2nd reselect example #10

Open
wants to merge 1 commit into
base: reselect2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion containers/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const matchingVisibleTodosSelector = createSelector(
selectMatchingTodos
);

const select = createStructuredSelector({
export const select = createStructuredSelector({
matchingVisibleTodos: matchingVisibleTodosSelector,
visibilityFilter: visibilityFilterSelector,
currentTheme: currentThemeSelector,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@
"babel-core": "^5.6.18",
"babel-loader": "^5.1.4",
"babel-plugin-react-transform": "^1.1.0",
"chai": "^3.4.0",
"expect": "^1.8.0",
"express": "^4.13.3",
"jsdom": "^5.6.1",
"mocha": "^2.2.5",
"mocha": "^2.3.3",
"node-libs-browser": "^0.5.2",
"raw-loader": "^0.5.1",
"react-addons-test-utils": "^0.14.0",
Expand Down
1 change: 1 addition & 0 deletions test/setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import chai from 'chai';
50 changes: 50 additions & 0 deletions test/specs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { expect } from 'chai';

import { select } from '../containers/App';

describe('App', () => {
describe('select function', () => {

describe('matchingVisibleTodos', () => {
const allTodos = [
{ text: 'a', completed: false },
{ text: 'ab', completed: true },
{ text: 'b', completed: false },
{ text: 'bc', completed: true }
];

it('returns all todos with empty search term and SHOW_ALL filter', () => {
const state = {
todos: allTodos,
searchTerm: '',
visibilityFilter: 'SHOW_ALL'
};
expect(select(state).matchingVisibleTodos).to.eql(allTodos);
});

it('applies visibilty filter', () => {
const state = {
todos: allTodos,
searchTerm: '',
visibilityFilter: 'SHOW_COMPLETED'
};
expect(select(state).matchingVisibleTodos).to.eql([
{ text: 'ab', completed: true },
{ text: 'bc', completed: true }
]);
});

it('applies the search term', () => {
const state = {
todos: allTodos,
searchTerm: 'a',
visibilityFilter: 'SHOW_ALL'
};
expect(select(state).matchingVisibleTodos).to.eql([
{ text: 'a', completed: false },
{ text: 'ab', completed: true }
]);
});
});
});
});