-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Snapshot testing with Dynamic Components
- Loading branch information
1 parent
1de8ac0
commit c9f8873
Showing
21 changed files
with
1,629 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"setupFiles": [ | ||
"raf/polyfill", | ||
"<rootDir>/src/tests/setupTests.js" | ||
], | ||
"snapshotSerializers": [ | ||
"enzyme-to-json/serializer" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import {addExpense, removeExpense, editExpense} from '../../actions/expenses'; | ||
|
||
|
||
test('Should setup remove expense object', ()=>{ | ||
const action = removeExpense({id:'123acb'}); | ||
expect(action).toEqual({ | ||
type: 'REMOVE_EXPENSE', | ||
id:'123acb' | ||
}); | ||
}); | ||
|
||
test('should setup edit expense object', ()=>{ | ||
const action = editExpense('123ab',{note:'edit note value'}); | ||
expect(action).toEqual({ | ||
type: 'EDIT_EXPENSE', | ||
id:'123ab', | ||
updates:{note:'edit note value'} | ||
}); | ||
}); | ||
|
||
test('should set up add expense action object with provided values',()=>{ | ||
const expenseData = { | ||
description:'this is add expense', | ||
note:'yo yo', | ||
amount:123, | ||
createdAt:123123 | ||
|
||
}; | ||
const action = addExpense(expenseData); | ||
expect(action).toEqual({ | ||
type:'ADD_EXPENSE', | ||
expense:{ | ||
...expenseData, | ||
id:expect.any(String) | ||
} | ||
}); | ||
}); | ||
|
||
test('should set up add expense action object with default values',()=>{ | ||
const expenseData = { | ||
description:'', | ||
note:'', | ||
amount:'', | ||
createdAt:'' | ||
}; | ||
const action= addExpense(expenseData); | ||
expect(action).toEqual({ | ||
type: 'ADD_EXPENSE', | ||
expense: { | ||
...expenseData, | ||
id:expect.any(String) | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import {setTextFilter,sortByAmount,sortByDate,setStartDate,setEndDate} from '../../actions/filters'; | ||
import moment from 'moment'; | ||
|
||
test('should generate action object for set start date action object', ()=>{ | ||
const action = setStartDate(moment(0)); | ||
expect(action).toEqual({ | ||
type:'SET_START_DATE', | ||
startDate:moment(0) | ||
}); | ||
}); | ||
|
||
test('should generate action object for set end date action object', ()=>{ | ||
const action = setEndDate(moment(0)); | ||
expect(action).toEqual({ | ||
type:'SET_END_DATE', | ||
endDate:moment(0) | ||
}); | ||
}); | ||
|
||
test('should generate action object for set text filter', ()=>{ | ||
const action = setTextFilter('bill'); | ||
expect(action).toEqual({ | ||
type: 'SET_TEXT_FILTER', | ||
text:'bill' | ||
}); | ||
}); | ||
|
||
test('should generate action object for sort by amount',()=>{ | ||
expect(sortByAmount()).toEqual({type:'SORT_BY_AMOUNT'}); | ||
}); | ||
|
||
test('should generate action object for sort by date',()=>{ | ||
expect(sortByDate()).toEqual({type:'SORT_BY_DATE'}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import ExpenseDashboardPage from '../../components/ExpenseDashboardPage'; | ||
import {shallow} from 'enzyme'; | ||
import toJSON from 'enzyme-to-json'; | ||
|
||
test('should render Expense Dashboard Page correctly',()=>{ | ||
const wrapper = shallow(< ExpenseDashboardPage/>); | ||
expect(toJSON(wrapper)).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import React from 'react'; | ||
import {shallow} from 'enzyme'; | ||
import {ExpenseList} from '../../components/ExpenseList'; | ||
import expenses from '../fixtures/expenses'; | ||
|
||
test('should render Expense List with expenses', ()=>{ | ||
const wrapper = shallow(<ExpenseList expenses = {expenses}/>); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); | ||
|
||
|
||
test('should render Expense List with no expenses', ()=>{ | ||
const wrapper = shallow(<ExpenseList expenses = {[]}/>); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import ExpenseListItem from '../../components/ExpenseListItem'; | ||
import expenses from '../fixtures/expenses'; | ||
|
||
test('should render Expense list item', ()=>{ | ||
const wrapper = shallow(<ExpenseListItem {...expenses[1]}/>); | ||
expect(wrapper).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import React from 'react'; | ||
import Header from '../../components/Header'; | ||
import {shallow} from 'enzyme'; | ||
import toJSON from 'enzyme-to-json'; | ||
import ReactShallowRenderer from 'react-test-renderer/shallow'; | ||
|
||
test('should render Header correctly',()=>{ | ||
const wrapper = shallow(<Header />); | ||
expect(toJSON(wrapper)).toMatchSnapshot(); | ||
// const renderer = new ReactShallowRenderer(); | ||
// renderer.render(<Header />); | ||
// expect(renderer.getRenderOutput()).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import NotFoundPage from '../../components/NotFoundPage'; | ||
import {shallow} from 'enzyme'; | ||
import toJSON from 'enzyme-to-json'; | ||
|
||
test('should render Not Found Page correctly',()=>{ | ||
const wrapper = shallow(< NotFoundPage />); | ||
expect(toJSON(wrapper)).toMatchSnapshot(); | ||
}); |
8 changes: 8 additions & 0 deletions
8
src/tests/components/__snapshots__/ExpenseDashboardPage.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render Expense Dashboard Page correctly 1`] = ` | ||
<div> | ||
<Connect(ExpenseList) /> | ||
<Connect(ExpenseListFilters) /> | ||
</div> | ||
`; |
38 changes: 38 additions & 0 deletions
38
src/tests/components/__snapshots__/ExpenseList.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render Expense List with expenses 1`] = ` | ||
<div> | ||
<ExpenseListItem | ||
amount={195} | ||
createdAt={0} | ||
description="aaa" | ||
id="0" | ||
key="0" | ||
note="ajanscjla" | ||
/> | ||
<ExpenseListItem | ||
amount={109500} | ||
createdAt={-345600000} | ||
description="sssaak" | ||
id="1" | ||
key="1" | ||
note="scjla" | ||
/> | ||
<ExpenseListItem | ||
amount={4500} | ||
createdAt={345600000} | ||
description="aako" | ||
id="2" | ||
key="2" | ||
note="anscjla" | ||
/> | ||
</div> | ||
`; | ||
|
||
exports[`should render Expense List with no expenses 1`] = ` | ||
<div> | ||
<p> | ||
No Expenses | ||
</p> | ||
</div> | ||
`; |
21 changes: 21 additions & 0 deletions
21
src/tests/components/__snapshots__/ExpenseListItem.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render Expense list item 1`] = ` | ||
<div> | ||
<Link | ||
replace={false} | ||
to="/edit/1" | ||
> | ||
<h3> | ||
sssaak | ||
</h3> | ||
</Link> | ||
<p> | ||
109500 | ||
- | ||
-345600000 | ||
</p> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render Header correctly 1`] = ` | ||
<header> | ||
<h1> | ||
Expensify App | ||
</h1> | ||
<NavLink | ||
activeClassName="is-active" | ||
ariaCurrent="true" | ||
exact={true} | ||
to="/" | ||
> | ||
Dashboard | ||
</NavLink> | ||
<NavLink | ||
activeClassName="is-active" | ||
ariaCurrent="true" | ||
to="/create" | ||
> | ||
Create Expense | ||
</NavLink> | ||
<NavLink | ||
activeClassName="is-active" | ||
ariaCurrent="true" | ||
to="/help" | ||
> | ||
Help | ||
</NavLink> | ||
</header> | ||
`; |
13 changes: 13 additions & 0 deletions
13
src/tests/components/__snapshots__/NotFoundPage.test.js.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`should render Not Found Page correctly 1`] = ` | ||
<div> | ||
NotFoundPage - | ||
<Link | ||
replace={false} | ||
to="/" | ||
> | ||
Go Home | ||
</Link> | ||
</div> | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import moment from 'moment'; | ||
|
||
|
||
export default [{ | ||
id:'0', | ||
description : 'aaa', | ||
note:'ajanscjla', | ||
amount:195, | ||
createdAt:0 | ||
},{ | ||
id: '1', | ||
description : 'sssaak', | ||
note:'scjla', | ||
amount:109500, | ||
createdAt:moment(0).subtract(4,'days').valueOf() | ||
},{ | ||
id: '2', | ||
description : 'aako', | ||
note:'anscjla', | ||
amount:4500, | ||
createdAt: moment(0).add(4,'days').valueOf() | ||
}]; | ||
|
Oops, something went wrong.