Skip to main content

Posts

How to add push notifications to React Web app with Firebase

https://www.freecodecamp.org/news/how-to-add-push-notifications-to-a-web-app-with-firebase-528a702e13e1/ ReactDOM . render ( < ThemeProvider theme = { theme } > { /* CssBaseline kickstart an elegant, consistent, and simple baseline to build upon. */ } < CssBaseline /> < AppContextProvider > < App /> </ AppContextProvider > </ ThemeProvider > , document . querySelector ( '#root' ) ) initializeFirebase () push-notification.ts import firebase from 'firebase' export const initializeFirebase = () => { if ( 'serviceWorker' in navigator ) { 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 ...

codegen for front end - react+graphQl

https://hasura.io/learn/graphql/typescript-react-apollo/codegen/ 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' ], }, }, } instal...

MOCK STRIPE

https://github.com/stripe/react-stripe-js/blob/master/src/components/Elements.tsx export const mockElement = () => ({ mount : jest . fn (), destroy : jest . fn (), on : jest . fn (), update : jest . fn (), }) export const mockElements = () => { const elements = {} return { create : jest . fn ( type => { return mockElement () }), getElement : jest . fn ( type => { return mockElement }), } } export const mockStripe = () => ({ 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 (), }) import * as stripeMocks from './stripe-mocks' const renderComponen...

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 possible Mount/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, ther...

react test with apollo

react: https://testing-library.com/docs/react-testing-library/setup ======= with 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 https://www.apollographql.com/docs/react/api/react-testing/ ======== Watch "Fix the "not wrapped in act(...)" warning" on egghead.io https://kentcdodds.com/blog/fix-the-not-wrapped-in-act-warning

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 ); } return inner ; // this returns a function } var fnc = outer (); // execute outer to get inner fnc (); As you might be able to guess, when I call  fnc()  it prints the value of  a , which is "1". =========================== function add (a) { return function (b) { return a + b; } } var add3 = add(3); add3(4); // returns 7 ======================== var  add = ( function  () {    var  counter =  0 ;    return   function  () {counter +=  1 ;  return  counter} })(); add(); add(); add(); // the coun...