Posts

MOCK STRIPE

const mockElement = () => ({ mount: jest.fn(), destroy: jest.fn(), on: jest.fn(), update: jest.fn(), }) const mockElements = () => { const elements = {}; return { create: jest.fn((type) => { elements[type] = mockElement(); return elements[type]; }), getElement: jest.fn((type) => { return elements[type] || null; }), } } const mockStripe = () => ({ elements: jest.fn(() => mockElements()), createToken: jest.fn(), createSource: jest.fn(), createPaymentMethod: jest.fn(), confirmCardPayment: jest.fn(), confirmCardSetup: jest.fn(), paymentRequest: jest.fn(), _registerWrapper: jest.fn(), }) jest.mock('@stripe/react-stripe-js', () => { const stripe = jest.requireActual('@stripe/react-stripe-js') return ({ ...stripe, Element: () => { return mockElement }, useStripe: () => { return mockStripe }, useElements: () => { return mockElements …

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: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-testinghttps://www.apollographql.com/docs/react/api/react-testing/========Watch "Fix the "not wrapped in act(...)" warning" on egghead.iohttps://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);

functional programming - clojure - immutable -

padestal.io
https://clojure.org/index
Atoms, Reducers, Agents/ActionsImmutable Data and React
https://www.youtube.com/watch?v=I7IdS-PbEgI&feature=youtu.bepersistent data structure


GraphQL Code Generator

https://graphql-code-generator.com/docs/plugins/typescript-react-apollo
TypeScript React ApolloIn order to use this package, please make sure that you have GraphQL operations set as documents: ... in your codegen.yml.Without loading your GraphQL operations (query, mutation, subscription and fragment), you won't see any change in the generated output.InstallationCopy$ yarn add @graphql-codegen/typescript-react-apollo

Testing Recipes