Skip to content

Instantly share code, notes, and snippets.

View Sidnioulz's full-sized avatar
🐿️

Steve Dodier-Lazaro Sidnioulz

🐿️
View GitHub Profile
From d22f3e8d4bbd6c06559f9f14f39f27ba79b64252 Mon Sep 17 00:00:00 2001
From: Steve Dodier-Lazaro <sidnioulz@gmail.com>
Date: Thu, 22 Jan 2015 02:21:37 +0000
Subject: [PATCH] Prevents passing wrong types to Bn constructors. Fixes issue
#2
---
petlib/bn.py | 2 ++
1 file changed, 2 insertions(+)
From ea29d4381fb2c10835b11f5ec7d67a438278db0d Mon Sep 17 00:00:00 2001
From: Steve Dodier-Lazaro <sidnioulz@gmail.com>
Date: Thu, 22 Jan 2015 15:50:31 +0000
Subject: [PATCH] First attempt at a Markdown documentation
---
Lab01Basics/Lab01Readme.txt | 202 -------------------------------------------
Lab01Basics/README.md | 203 ++++++++++++++++++++++++++++++++++++++++++++
README.md | 9 ++
3 files changed, 212 insertions(+), 202 deletions(-)
@Sidnioulz
Sidnioulz / LJNSagaTesting01.js
Created November 30, 2021 13:32
Saga testing example from the official documentation
// Saga
function* doStuffThenChangeColor() {
yield put(doStuff());
yield put(doStuff());
const action = yield take(CHOOSE_NUMBER);
if (action.payload.number % 2 === 0) {
yield put(changeUI('red'));
} else {
yield put(changeUI('blue'));
}
@Sidnioulz
Sidnioulz / LJNSagaTesting02.js
Created November 30, 2021 13:33
Simplified version of our saga test runner
function configureStore(someSaga, someReducer, initialState = {}) {
const dispatched = []
const sagaMiddleware = createSagaMiddleware({
sagaMonitor: {
actionDispatched: (action) => dispatched.push(action),
},
})
const store = createStore(moduleReducer, initialState, applyMiddleware(sagaMiddleware))
@Sidnioulz
Sidnioulz / LJNSagaTesting03.js
Created November 30, 2021 13:33
Sample saga test
describe('loginSaga', () => {
it('logs a user in when the email and password are recognised', async () => {
const { store, dispatched } = configureStore()
/* Arrange */
const expirationDate = getFutureDate({ minute: 15 })
mockAxiosSuccess({ expirationDate }) // /auth/login
mockAxiosSuccess(annieErnaux) // /auth/fetchCurrentUser
/* Act */
@Sidnioulz
Sidnioulz / LJNSagaTesting04.js
Created November 30, 2021 13:34
Basic backend API mock functions
import axios from 'axios'
jest.mock('axios')
export const mockAxiosSuccess = (data, status = 200) => {
axios.mockResolvedValueOnce({ data, status })
}
export const mockAxiosFailure = (data, status = null) => {
axios.mockRejectedValueOnce({
@Sidnioulz
Sidnioulz / LJNSagaTesting05.js
Created November 30, 2021 13:35
expectAction utility function
import { waitFor } from '@testing-library/react'
export const expectAction = async (dispatched, action) => {
await waitFor(() => expect(dispatched[dispatched.length - 1]).toMatchObject(action))
}
@Sidnioulz
Sidnioulz / LJNSagaTesting06.js
Created November 30, 2021 13:36
Redux Dynamic Modules example
import { DynamicModuleLoader } from 'redux-dynamic-modules'
import React from 'react'
import { startup } from 'modules/auth/actions/authActions'
import authReducer from 'modules/auth/reducers/authReducer'
import redirectReducer from 'modules/redirect/reducers/redirectReducer'
import authSaga from 'modules/auth/sagas/authSaga'
import redirectSaga from 'modules/redirect/sagas/redirectSaga'
@Sidnioulz
Sidnioulz / LJNSagaTesting07.js
Created November 30, 2021 13:36
How to import a Redux Dynamic Module
const Auth = lazy(() => import(/* webpackPrefetch: true */ 'modules/auth'))
@Sidnioulz
Sidnioulz / LJNSagaTesting08.js
Created November 30, 2021 13:37
Saga test runner generator for Redux Dynamic Modules
export function makeTestRunner(dynamicModule) {
const moduleReducer = combineReducers(dynamicModule.reducerMap)
function* moduleTestSaga() {
for (const saga of dynamicModule.sagas) {
yield fork(saga)
}
}
return function configureStore(initialState = {}) {