This file contains hidden or 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
| expect.extend({ | |
| toBePowerOf(received, power) { | |
| if (typeof power !== 'number') { | |
| throw new Error('expected power to be a number'); | |
| } | |
| if (typeof received !== 'number') { | |
| throw new Error('expected value to be a number'); | |
| } | |
This file contains hidden or 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
| expect.extend({ | |
| toBeISODate(received) { | |
| // This regexp checks for formatting | |
| if ( | |
| !/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.\d{3}Z/.test(received) | |
| ) { | |
| return { | |
| pass: false, | |
| message: `Expected ${received} to be a valid ISO date string`, | |
| }; |
This file contains hidden or 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
| "preset": "jest-expo", | |
| "projects": [ | |
| { | |
| "preset": "jest-expo/ios", | |
| "setupFilesAfterEnv": [ | |
| "./setupJestAfterEnv.js" | |
| ] | |
| }, | |
| { | |
| "preset": "jest-expo/android", |
This file contains hidden or 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
| expect(1).toBe(1); // Checking for value and reference equality | |
| expect({a: 'b'}).toEqual({a: 'b'}); //Checking for deep value equality | |
| expect('abacaba').toMatch(/bac/); // Checking if a string matches a regexp | |
| expect({a: 'b', b: 'c'}).toMatchObject({a: 'b'}); // Checking for a partial object match | |
| expect([1, 2, 3]).toContainEqual(2); // Checking if an array contains an element | |
| expect(2).not.toEqual(3); // using not to negate any matcher | |
| expect({a: 'b'}).toMatchObject({ | |
| a: expect.any(String) | |
| }); // Type checking |
This file contains hidden or 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
| import { applyMiddleware, createStore } from 'redux'; | |
| import reducer from 'WHERE YOUR REDUCER IS'; | |
| import interceptorMiddleware from 'WHERE YOUR MIDDLEWARE IS'; | |
| const store = createStore( | |
| reducer, | |
| undefined, // initial state, none in this case | |
| applyMiddleware(interceptorMiddleware) | |
| ); | |
| export default store; |
This file contains hidden or 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
| const createInterceptorMiddleware = (interceptors) => (store) => (next) => (action) => { | |
| Promise.all( | |
| interceptors | |
| .filter(interceptor => interceptor.type === action.type) | |
| .map(interceptor => { | |
| const result = interceptor.handler(action, store.dispatch, store.getState); | |
| return result instanceof Promise ? result : Promise.resolve(result); | |
| }) | |
| ) | |
| .then((afterDispatchHandlers) => { |
This file contains hidden or 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
| const createInterceptorMiddleware = (interceptors) => (store) => (next) => (action) => { | |
| Promise.all( | |
| interceptors | |
| .filter(interceptor => interceptor.type === action.type) | |
| .map(interceptor => { | |
| const result = interceptor.handler(action, store.dispatch, store.getState); | |
| return result instanceof Promise ? result : Promise.resolve(result); | |
| }) | |
| ) | |
| .then(() => next(action)) |
This file contains hidden or 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
| const createInterceptorMiddleware = (interceptors) => (store) => (next) => (action) => { | |
| interceptors | |
| .filter(interceptor => interceptor.type === action.type) | |
| .forEach(interceptor => interceptor.handler(action, store.dispatch, store.getState)); | |
| next(action); | |
| } | |
| const interceptors = [ | |
| {type: 'INCREMENT', handler: () => doSomeApiStuff()}, |
This file contains hidden or 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
| const loggingMiddleware = (store) => (next) => (action) => { | |
| console.log(action.type); | |
| next(action); | |
| }; |
This file contains hidden or 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
| const {createStore} from 'redux'; | |
| // this is how state looks initially | |
| const INITIAL_STATE = { | |
| counter: 0 | |
| }; | |
| function reducer(state=INITIAL_STATE, action) { | |
| // this function will return a new state | |
| // based on action |