-
Notifications
You must be signed in to change notification settings - Fork 105
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
chore(Bonus Pagamenti Digitali): [#175636284] Add tests for bpdsummarycomponent & bpdAllPeriodsWithAmountSelector #2352
Conversation
Affected stories
New dependencies added: @testing-library/jest-nativeAuthor: Brandon Carroll Description: Custom jest matchers to test the state of React Native Homepage: https://github.com/testing-library/jest-native#readme
@testing-library/react-nativeAuthor: Michał Pierzchała Description: Simple and complete React Native testing utilities that encourage good testing practices. Homepage: https://callstack.github.io/react-native-testing-library
|
Created | over 4 years ago |
Last Updated | about 13 hours ago |
License | MIT |
Maintainers | 1 |
Releases | 17 |
Direct Dependencies | redux |
README
Installation
npm install --save @types/redux-mock-store
Summary
This package contains type definitions for Redux Mock Store (https://github.com/dmitry-zaets/redux-mock-store).
Details
Files were exported from https://github.com/DefinitelyTyped/DefinitelyTyped/tree/master/types/redux-mock-store.
Additional Details
- Last updated: Mon, 27 Jan 2020 22:31:33 GMT
- Dependencies: @types/redux
- Global values: none
Credits
These definitions were written by Marian Palkus (https://github.com/MarianPalkus), and Cap3 (http://www.cap3.de).
mockdate
Author: Bob Lauer
Description: A JavaScript mock Date object that can be used to change when "now" is.
Homepage: https://github.com/boblauer/MockDate
Created | over 6 years ago |
Last Updated | 6 months ago |
License | MIT |
Maintainers | 1 |
Releases | 16 |
Direct Dependencies | |
Keywords | date, mock and test |
README
MockDate
A JavaScript Mock Date object that can be used to change when "now" is.
Installation
npm install mockdate
Environment Support
MockDate has been tested in Node, IE9+, Chrome, Firefox, and Opera.
Usage
import MockDate from 'mockdate'
API
MockDate.set(date)
date
date: Object
The Date
to be returned when no parameters are passed to new Date()
. Supports any object that has a .valueOf
method that returns a value that can be passed to new Date()
.
date: String
The string representation of the date which is passed to the new Date()
constructor. This creates the Date
to be returned when no parameters are passed to new Date()
.
date: Number
The millisecond representation of the Date
to be returned when no parameters are passed to new Date()
.
MockDate.reset();
Will restore the original Date
object back to the native implementation.
Example
MockDate.set('2000-11-22');
new Date().toString() // "Tue Nov 21 2000 18:00:00 GMT-0600 (CST)"
MockDate.set('1/30/2000');
new Date().toString() // "Sun Jan 30 2000 00:00:00 GMT-0600 (CST)"
MockDate.set(new Date('2/20/2000'));
new Date().toString() // "Sun Feb 20 2000 00:00:00 GMT-0600 (CST)"
MockDate.set(moment('3/30/2000').toDate()); // using momentjs
new Date().toString() // "Thu Mar 30 2000 00:00:00 GMT-0600 (CST)"
MockDate.reset();
new Date().toString() // "Mon Mar 17 2014 18:08:44 GMT-0500 (CDT)"
Test
npm test
redux-mock-store
Author: Arnaud Benard
Description: A mock store for testing your redux async action creators and middleware
Homepage: https://github.com/arnaudbenard/redux-mock-store#readme
Created | about 5 years ago |
Last Updated | 11 months ago |
License | MIT |
Maintainers | 2 |
Releases | 26 |
Direct Dependencies | lodash.isplainobject |
README
redux-mock-store 
A mock store for testing Redux async action creators and middleware. The mock store will create an array of dispatched actions which serve as an action log for tests.
Please note that this library is designed to test the action-related logic, not the reducer-related one. In other words, it does not update the Redux store. If you want a complex test combining actions and reducers together, take a look at other libraries (e.g., redux-actions-assertions). Refer to issue #71 for more details.
Install
npm install redux-mock-store --save-dev
Or
yarn add redux-mock-store --dev
Usage
Synchronous actions
The simplest usecase is for synchronous actions. In this example, we will test if the addTodo
action returns the right payload. redux-mock-store
saves all the dispatched actions inside the store instance. You can get all the actions by calling store.getActions()
. Finally, you can use any assertion library to test the payload.
import configureStore from 'redux-mock-store' //ES6 modules
const { configureStore } = require('redux-mock-store') //CommonJS
const middlewares = []
const mockStore = configureStore(middlewares)
// You would import the action from your codebase in a real scenario
const addTodo = () => ({ type: 'ADD_TODO' })
it('should dispatch action', () => {
// Initialize mockstore with empty state
const initialState = {}
const store = mockStore(initialState)
// Dispatch the action
store.dispatch(addTodo())
// Test if your store dispatched the expected actions
const actions = store.getActions()
const expectedPayload = { type: 'ADD_TODO' }
expect(actions).toEqual([expectedPayload])
})
Asynchronous actions
A common usecase for an asynchronous action is a HTTP request to a server. In order to test those types of actions, you will need to call store.getActions()
at the end of the request.
import configureStore from 'redux-mock-store'
import thunk from 'redux-thunk'
const middlewares = [thunk] // add your middlewares like `redux-thunk`
const mockStore = configureStore(middlewares)
// You would import the action from your codebase in a real scenario
function success() {
return {
type: 'FETCH_DATA_SUCCESS'
}
}
function fetchData () {
return dispatch => {
return fetch('/users.json') // Some async action with promise
.then(() => dispatch(success()))
};
}
it('should execute fetch data', () => {
const store = mockStore({})
// Return the promise
return store.dispatch(fetchData())
.then(() => {
const actions = store.getActions()
expect(actions[0]).toEqual(success())
})
})
API
configureStore(middlewares?: Array) => mockStore: Function
Configure mock store by applying the middlewares.
mockStore(getState?: Object,Function) => store: Function
Returns an instance of the configured mock store. If you want to reset your store after every test, you should call this function.
store.dispatch(action) => action
Dispatches an action through the mock store. The action will be stored in an array inside the instance and executed.
store.getState() => state: Object
Returns the state of the mock store.
store.getActions() => actions: Array
Returns the actions of the mock store.
store.clearActions()
Clears the stored actions.
store.subscribe(callback: Function) => unsubscribe: Function
Subscribe to the store.
store.replaceReducer(nextReducer: Function)
Follows the Redux API.
Old version (< 1.x.x
)
https://github.com/arnaudbenard/redux-mock-store/blob/v0.0.6/README.md
License
The MIT License
Codecov Report
@@ Coverage Diff @@
## master #2352 +/- ##
==========================================
+ Coverage 48.84% 49.22% +0.38%
==========================================
Files 631 633 +2
Lines 17714 17721 +7
Branches 3490 3490
==========================================
+ Hits 8652 8724 +72
+ Misses 9020 8954 -66
- Partials 42 43 +1
Continue to review full report at Codecov.
|
Short description
This pr adds some test for
BPDSummaryComponent
andbpdAllPeriodsWithAmountSelector
.How to test
ts/features/bonus/bpd/screens/details/components/summary/__test__/bpdSummaryComponent.test.tsx
ts/features/bonus/bpd/store/reducers/details/__test__/combiner.test.ts