How to add push notifications to React Web app with Firebase
ReactDOM.render( <ThemeProvidertheme={theme}> {/* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */} <CssBaseline/> <AppContextProvider> <App/> </AppContextProvider> </ThemeProvider>, document.querySelector('#root') )

push-notification.ts importfirebasefrom'firebase'
exportconstinitializeFirebase = () => { if ('serviceWorker'innavigator) { navigator.serviceWorker .register('./firebase-messaging-sw.js') .then(function (registration) { console.log('Registration successful, scope is:', registration.scope) }) .catch(function (err) { console.log('Service worker registration failed, error:', err) }) } }
exportconstaskForPermissioToReceiveNotifications = async () => { try { constmessaging = firebase.messaging() awaitmessaging.requestPermission…

codegen for front end - react+graphQl
fix: anonymous query for codegen - getCurrentAccount
package.json: "codegen": "graphql-codegen --config codegen.js" codegen.js module.exports = { schema: [ { 'http://localhost:4000/graphql': { headers: { Authorization:'Bearer ' + process.env.AUTH_TOKEN, }, }, }, ], documents: ['./src/**/*.tsx', './src/**/*.ts'], overwrite:true, generates: { './src/generated/graphql.tsx': { plugins: [ 'typescript', 'typescript-operations', 'typescript-react-apollo', ], config: { skipTypename:false, withHooks:true, withHOC:false, withComponent:false, }, }, './graphql.schema.json': { plugins: ['introspection'], }, }, }
install: yarn add @graphql-codegen/cli @graphql-codegen/introspection @graphql-codegen/typescript @graphql-codegen/typescript-operations @graphql-codegen/typescript

MOCK STRIPE = () => ({ mount:jest.fn(), destroy:jest.fn(), on:jest.fn(), update:jest.fn(), })
exportconstmockElements = () => { constelements = {} return { create:jest.fn(type=> { returnmockElement() }), getElement:jest.fn(type=> { returnmockElement }), } }
exportconstmockStripe = () => ({ elements:jest.fn(() =>mockElements()), createToken:jest.fn(), createSource:jest.fn(), createPaymentMethod:jest.fn(), confirmCardPayment:jest.fn(() => { return { paymentIntent: { id:'test', status:'succeeded' } } }), confirmCardSetup:jest.fn(), paymentRequest:jest.fn(), _registerWrapper:jest.fn(), })
constrenderComponent = () => { conststripe = stripeMocks.mockStripe()
returnrender( <MockedProvidermocks={mocks}addTypename={false}> <CartProvider> <Elementsstripe={stripe}> <Payment listingId={listingId} currentPackage={currentPac…

how to do integration test - react app - Cypress (e to e)

Many integration tests. No snapshot tests. Few unit tests. Few e to e tests.
Integration tests should mock as little as possibleMount/render is typically used for integration testing and shallow is used for unit testing.shallow rendering only renders the single component we are testing. It does not render child components. This allows us to test our component in isolation. unit vs integration vs end to end unit testing: testing an isolated part of your app, usually done in combination with shallow rendering. example: a component renders with the default props. integration testing: testing if different parts work or integrate with each other. Usually done with mounting or rendering a component. example: test if a child component can update context state in a parent. e to e testing: Stands for end to end. Usually a multi step test combining multiple unit and integration tests into one big test. Usually very little is mocked or stubbed. Tests are done in a simulated browser, there may or may …

react test with apollo

react: apollo:Note: As of React Apollo 3, all testing utilities can now be found in their own @apollo/react-testing package.
npm install @apollo/react-testing "Fix the "not wrapped in act(...)" warning" on egghead.io

A closure is a persistent local variable scope

Languages which support closure (such as JavaScript, Swift, and Ruby) will allow you to keep a reference to a scope (including its parent scopes), even after the block in which those variables were declared has finished executing, provided you keep a reference to that block or function somewhere.

outer =function(){var a =1;var inner =function(){ console.log(a);

functional programming - clojure - immutable -
Atoms, Reducers, Agents/ActionsImmutable Data and React data structure