Best JavaScript code snippet using playwright-internal
selector.test.js
Source:selector.test.js
1import MockRealm, { MockQuery } from 'realm';2import { pureFinalPropsSelectorFactory } from '../src/connect/selectorFactory';3describe('selectorFactory', () => {4 const realm = new MockRealm();5 const Query = jest.fn(() => new MockQuery());6 const query1 = new Query();7 const query2 = new Query();8 const queries = [query1, query2];9 const queryProps = { queryProps: true };10 const dispatchProps = { dispatchProps: true };11 const finalProps = {12 ...queryProps,13 ...dispatchProps14 };15 const mapPropsToQueries = jest.fn();16 const mapQueriesToProps = jest.fn();17 const mapDispatchToProps = jest.fn();18 const mergeProps = jest.fn();19 const dispatch = jest.fn();20 const areOwnPropsEqual = jest.fn();21 const areQueryPropsEqual = jest.fn();22 beforeEach(() => {23 mapPropsToQueries.mockClear();24 mapPropsToQueries.mockImplementation(() => queries);25 mapPropsToQueries.dependsOnOwnProps = true;26 mapQueriesToProps.mockClear();27 mapQueriesToProps.mockImplementation(() => queryProps);28 mapQueriesToProps.dependsOnOwnProps = true;29 mapDispatchToProps.mockClear();30 mapDispatchToProps.mockImplementation(() => dispatchProps);31 mapDispatchToProps.dependsOnOwnProps = true;32 mergeProps.mockClear();33 mergeProps.mockImplementation(() => finalProps);34 dispatch.mockClear();35 query1.mockClear();36 query2.mockClear();37 realm.mockClear();38 areOwnPropsEqual.mockClear();39 areOwnPropsEqual.mockImplementation(() => false);40 areQueryPropsEqual.mockClear();41 areQueryPropsEqual.mockImplementation(() => false);42 });43 it('returns a function', () => {44 expect(typeof pureFinalPropsSelectorFactory(45 mapPropsToQueries,46 mapQueriesToProps,47 mapDispatchToProps,48 mergeProps,49 dispatch,50 {}51 )).toEqual('function');52 mergeProps.hello = true;53 });54 it('calls all the mapping functions to generate first props', () => {55 const firstProps = { customProp: 'test' };56 const selector = pureFinalPropsSelectorFactory(57 mapPropsToQueries,58 mapQueriesToProps,59 mapDispatchToProps,60 mergeProps.mockImplementation(() => { return { ...finalProps, ...firstProps }; }),61 dispatch,62 { areOwnPropsEqual, areQueryPropsEqual }63 );64 const nextProps = selector(realm, firstProps);65 expect(areQueryPropsEqual.mock.calls.length).toBe(0);66 expect(areOwnPropsEqual.mock.calls.length).toBe(0);67 expect(mapPropsToQueries.mock.calls.length).toBe(1);68 expect(mapPropsToQueries.mock.calls[0][0]).toBe(realm);69 expect(mapPropsToQueries.mock.calls[0][1]).toBe(firstProps);70 expect(mapQueriesToProps.mock.calls.length).toBe(1);71 expect(mapQueriesToProps.mock.calls[0][0]).toEqual(queries);72 expect(mapQueriesToProps.mock.calls[0][1]).toBe(firstProps);73 expect(mapDispatchToProps.mock.calls.length).toBe(1);74 expect(mapDispatchToProps.mock.calls[0][0]).toEqual(dispatch);75 expect(mapDispatchToProps.mock.calls[0][1]).toBe(firstProps);76 expect(mergeProps.mock.calls.length).toBe(1);77 expect(mergeProps.mock.calls[0][0]).toEqual(queryProps);78 expect(mergeProps.mock.calls[0][1]).toBe(dispatchProps);79 expect(mergeProps.mock.calls[0][2]).toBe(firstProps);80 expect(nextProps).toEqual({ ...finalProps, ...firstProps });81 });82 it('skips unnecessary mapPropsToQueries call when not dependent on ownProps', () => {83 const firstProps = { customProp: 'test' };84 const secondProps = { customProp: 'test2' };85 mapPropsToQueries.dependsOnOwnProps = false;86 const selector = pureFinalPropsSelectorFactory(87 mapPropsToQueries,88 mapQueriesToProps,89 mapDispatchToProps,90 mergeProps.mockImplementation(() => { return { ...finalProps, ...secondProps }; }),91 dispatch,92 { areOwnPropsEqual, areQueryPropsEqual }93 );94 selector(realm, firstProps);95 selector(realm, secondProps);96 expect(areOwnPropsEqual.mock.calls.length).toBe(1);97 expect(mapPropsToQueries.mock.calls.length).toBe(1);98 });99 it('skips unnecessary mapPropsToQueries call when ownProps didn\'t change', () => {100 const firstProps = { customProp: 'test' };101 const secondProps = { customProp: 'test2' };102 areOwnPropsEqual.mockImplementation(() => true);103 const selector = pureFinalPropsSelectorFactory(104 mapPropsToQueries,105 mapQueriesToProps,106 mapDispatchToProps,107 mergeProps.mockImplementation(() => { return { ...finalProps, ...secondProps }; }),108 dispatch,109 { areOwnPropsEqual, areQueryPropsEqual }110 );111 selector(realm, firstProps);112 selector(realm, secondProps);113 expect(areOwnPropsEqual.mock.calls.length).toBe(1);114 expect(mapPropsToQueries.mock.calls.length).toBe(1);115 });116 it('handles props changed and state changed when everything actually changed', () => {117 const firstProps = { customProp: 'test' };118 const secondProps = { customProp: 'test2' };119 const selector = pureFinalPropsSelectorFactory(120 mapPropsToQueries,121 mapQueriesToProps,122 mapDispatchToProps,123 mergeProps.mockImplementation(() => { return { ...finalProps, ...secondProps }; }),124 dispatch,125 { areOwnPropsEqual, areQueryPropsEqual }126 );127 selector(realm, firstProps);128 query1.triggerListeners({ insertions: [null] });129 const nextProps = selector(realm, secondProps);130 expect(areQueryPropsEqual.mock.calls.length).toBe(0);131 expect(areOwnPropsEqual.mock.calls.length).toBe(1);132 expect(mapPropsToQueries.mock.calls.length).toBe(2);133 expect(mapPropsToQueries.mock.calls[1][0]).toBe(realm);134 expect(mapPropsToQueries.mock.calls[1][1]).toBe(secondProps);135 expect(mapQueriesToProps.mock.calls.length).toBe(2);136 expect(mapQueriesToProps.mock.calls[1][0]).toEqual(queries);137 expect(mapQueriesToProps.mock.calls[1][1]).toBe(secondProps);138 expect(mapDispatchToProps.mock.calls.length).toBe(2);139 expect(mapDispatchToProps.mock.calls[1][0]).toEqual(dispatch);140 expect(mapDispatchToProps.mock.calls[1][1]).toBe(secondProps);141 expect(mergeProps.mock.calls.length).toBe(2);142 expect(mergeProps.mock.calls[1][0]).toEqual(queryProps);143 expect(mergeProps.mock.calls[1][1]).toBe(dispatchProps);144 expect(mergeProps.mock.calls[1][2]).toBe(secondProps);145 expect(nextProps).toEqual({ ...finalProps, ...secondProps });146 });147 it('handles props changed and state change and skips unnecessary mapDispatchToProps call', () => {148 const firstProps = { customProp: 'test' };149 const secondProps = { customProp: 'test2' };150 mapDispatchToProps.dependsOnOwnProps = false;151 const selector = pureFinalPropsSelectorFactory(152 mapPropsToQueries,153 mapQueriesToProps,154 mapDispatchToProps,155 mergeProps.mockImplementation(() => { return { ...finalProps, ...secondProps }; }),156 dispatch,157 { areOwnPropsEqual, areQueryPropsEqual }158 );159 selector(realm, firstProps);160 query1.triggerListeners({ insertions: [null] });161 const nextProps = selector(realm, secondProps);162 expect(areQueryPropsEqual.mock.calls.length).toBe(0);163 expect(areOwnPropsEqual.mock.calls.length).toBe(1);164 expect(mapPropsToQueries.mock.calls.length).toBe(2);165 expect(mapQueriesToProps.mock.calls.length).toBe(2);166 expect(mapDispatchToProps.mock.calls.length).toBe(1);167 expect(mergeProps.mock.calls.length).toBe(2);168 expect(nextProps).toEqual({ ...finalProps, ...secondProps });169 });170 it('handles props changed', () => {171 const firstProps = { customProp: 'test' };172 const secondProps = { customProp: 'test2' };173 mapPropsToQueries.dependsOnOwnProps = false;174 const selector = pureFinalPropsSelectorFactory(175 mapPropsToQueries,176 mapQueriesToProps,177 mapDispatchToProps,178 mergeProps.mockImplementation(() => { return { ...finalProps, ...secondProps }; }),179 dispatch,180 { areOwnPropsEqual, areQueryPropsEqual }181 );182 selector(realm, firstProps);183 const nextProps = selector(realm, secondProps);184 expect(areQueryPropsEqual.mock.calls.length).toBe(0);185 expect(areOwnPropsEqual.mock.calls.length).toBe(1);186 expect(mapPropsToQueries.mock.calls.length).toBe(1);187 expect(mapQueriesToProps.mock.calls.length).toBe(2);188 expect(mapDispatchToProps.mock.calls.length).toBe(2);189 expect(mergeProps.mock.calls.length).toBe(2);190 expect(nextProps).toEqual({ ...finalProps, ...secondProps });191 });192 it('handles props changed but skips unnecessary mapQueriestoProps and mapDispatchToProps', () => {193 const firstProps = { customProp: 'test' };194 const secondProps = { customProp: 'test2' };195 mapQueriesToProps.dependsOnOwnProps = false;196 mapDispatchToProps.dependsOnOwnProps = false;197 const selector = pureFinalPropsSelectorFactory(198 mapPropsToQueries,199 mapQueriesToProps,200 mapDispatchToProps,201 mergeProps.mockImplementation(() => { return { ...finalProps, ...secondProps }; }),202 dispatch,203 { areOwnPropsEqual, areQueryPropsEqual }204 );205 selector(realm, firstProps);206 const nextProps = selector(realm, secondProps);207 expect(areQueryPropsEqual.mock.calls.length).toBe(0);208 expect(areOwnPropsEqual.mock.calls.length).toBe(1);209 expect(mapPropsToQueries.mock.calls.length).toBe(2);210 expect(mapQueriesToProps.mock.calls.length).toBe(1);211 expect(mapDispatchToProps.mock.calls.length).toBe(1);212 expect(mergeProps.mock.calls.length).toBe(2);213 expect(nextProps).toEqual({ ...finalProps, ...secondProps });214 });215 it('triggers state change if queries changed', () => {216 const firstProps = { customProp: 'test' };217 const secondProps = { customProp: 'test2' };218 mapQueriesToProps.dependsOnOwnProps = false;219 mapDispatchToProps.dependsOnOwnProps = false;220 const selector = pureFinalPropsSelectorFactory(221 mapPropsToQueries,222 mapQueriesToProps,223 mapDispatchToProps,224 mergeProps.mockImplementation(() => { return { ...finalProps, ...secondProps }; }),225 dispatch,226 { areOwnPropsEqual, areQueryPropsEqual }227 );228 selector(realm, firstProps);229 mapPropsToQueries.mockImplementation(() => [query2, query1]);230 const nextProps = selector(realm, secondProps);231 expect(areQueryPropsEqual.mock.calls.length).toBe(0);232 expect(areOwnPropsEqual.mock.calls.length).toBe(1);233 expect(mapPropsToQueries.mock.calls.length).toBe(2);234 expect(mapQueriesToProps.mock.calls.length).toBe(2);235 expect(mapDispatchToProps.mock.calls.length).toBe(1);236 expect(mergeProps.mock.calls.length).toBe(2);237 expect(mergeProps.mock.calls[1][0]).toEqual(queryProps);238 expect(mergeProps.mock.calls[1][1]).toBe(dispatchProps);239 expect(mergeProps.mock.calls[1][2]).toBe(secondProps);240 expect(nextProps).toEqual({ ...finalProps, ...secondProps });241 });242 it('handles state changes', () => {243 const firstProps = { customProp: 'test' };244 areOwnPropsEqual.mockImplementation(() => true);245 const selector = pureFinalPropsSelectorFactory(246 mapPropsToQueries,247 mapQueriesToProps,248 mapDispatchToProps,249 mergeProps.mockImplementation(() => { return { ...finalProps, ...firstProps }; }),250 dispatch,251 { areOwnPropsEqual, areQueryPropsEqual }252 );253 selector(realm, firstProps);254 query1.triggerListeners({ insertions: [null] });255 const nextProps = selector(realm, firstProps);256 expect(areQueryPropsEqual.mock.calls.length).toBe(1);257 expect(areOwnPropsEqual.mock.calls.length).toBe(1);258 expect(mapPropsToQueries.mock.calls.length).toBe(1);259 expect(mapQueriesToProps.mock.calls.length).toBe(2);260 expect(mapDispatchToProps.mock.calls.length).toBe(1);261 expect(mergeProps.mock.calls.length).toBe(2);262 expect(nextProps).toEqual({ ...finalProps, ...firstProps });263 });264 it('handles state changes but skips unnecessary mergeProps calls', () => {265 const firstProps = { customProp: 'test' };266 areOwnPropsEqual.mockImplementation(() => true);267 areQueryPropsEqual.mockImplementation(() => true);268 const selector = pureFinalPropsSelectorFactory(269 mapPropsToQueries,270 mapQueriesToProps,271 mapDispatchToProps,272 mergeProps.mockImplementation(() => { return { ...finalProps, ...firstProps }; }),273 dispatch,274 { areOwnPropsEqual, areQueryPropsEqual }275 );276 selector(realm, firstProps);277 query1.triggerListeners({ insertions: [null] });278 const nextProps = selector(realm, firstProps);279 expect(areQueryPropsEqual.mock.calls.length).toBe(1);280 expect(areOwnPropsEqual.mock.calls.length).toBe(1);281 expect(mapPropsToQueries.mock.calls.length).toBe(1);282 expect(mapQueriesToProps.mock.calls.length).toBe(2);283 expect(mapDispatchToProps.mock.calls.length).toBe(1);284 expect(mergeProps.mock.calls.length).toBe(1);285 expect(nextProps).toEqual({ ...finalProps, ...firstProps });286 });...
react-redux_v7.x.x.js
Source:react-redux_v7.x.x.js
1// flow-typed signature: 8da1e134b3de1d6f6bf9ba1cc7e2dc7e2// flow-typed version: 387a235736/react-redux_v7.x.x/flow_>=v0.104.x3/**4The order of type arguments for connect() is as follows:5connect<Props, OwnProps, StateProps, DispatchProps, State, Dispatch>(â¦)6In Flow v0.89 only the first two are mandatory to specify. Other 4 can be repaced with the new awesome type placeholder:7connect<Props, OwnProps, _, _, _, _>(â¦)8But beware, in case of weird type errors somewhere in random places9just type everything and get to a green field and only then try to10remove the definitions you see bogus.11Decrypting the abbreviations:12 WC = Component being wrapped13 S = State14 D = Dispatch15 OP = OwnProps16 SP = StateProps17 DP = DispatchProps18 MP = Merge props19 RSP = Returned state props20 RDP = Returned dispatch props21 RMP = Returned merge props22 CP = Props for returned component23 Com = React Component24 SS = Selected state25 ST = Static properties of Com26 EFO = Extra factory options (used only in connectAdvanced)27*/28declare module "react-redux" {29 // ------------------------------------------------------------30 // Typings for connect()31 // ------------------------------------------------------------32 declare export type Options<S, OP, SP, MP> = {|33 pure?: boolean,34 forwardRef?: boolean,35 areStatesEqual?: (next: S, prev: S) => boolean,36 areOwnPropsEqual?: (next: OP, prev: OP) => boolean,37 areStatePropsEqual?: (next: SP, prev: SP) => boolean,38 areMergedPropsEqual?: (next: MP, prev: MP) => boolean,39 storeKey?: string,40 |};41 declare type MapStateToProps<-S, -OP, +SP> =42 | ((state: S, ownProps: OP) => SP)43 // If you want to use the factory function but get a strange error44 // like "function is not an object" then just type the factory function45 // like this:46 // const factory: (State, OwnProps) => (State, OwnProps) => StateProps47 // and provide the StateProps type to the SP type parameter.48 | ((state: S, ownProps: OP) => (state: S, ownProps: OP) => SP);49 declare type Bind<D> = <A, R>((...A) => R) => (...A) => $Call<D, R>;50 declare type MapDispatchToPropsFn<D, -OP, +DP> =51 | ((dispatch: D, ownProps: OP) => DP)52 // If you want to use the factory function but get a strange error53 // like "function is not an object" then just type the factory function54 // like this:55 // const factory: (Dispatch, OwnProps) => (Dispatch, OwnProps) => DispatchProps56 // and provide the DispatchProps type to the DP type parameter.57 | ((dispatch: D, ownProps: OP) => (dispatch: D, ownProps: OP) => DP);58 declare class ConnectedComponent<OP, +WC> extends React$Component<OP> {59 static +WrappedComponent: WC;60 getWrappedInstance(): React$ElementRef<WC>;61 }62 // The connection of the Wrapped Component and the Connected Component63 // happens here in `MP: P`. It means that type wise MP belongs to P,64 // so to say MP >= P.65 declare type Connector<P, OP, MP: P> = <WC: React$ComponentType<P>>(66 WC,67 ) => Class<ConnectedComponent<OP, WC>> & WC;68 // No `mergeProps` argument69 // Got error like inexact OwnProps is incompatible with exact object type?70 // Just make the OP parameter for `connect()` an exact object.71 declare type MergeOP<OP, D> = {| ...$Exact<OP>, dispatch: D |};72 declare type MergeOPSP<OP, SP, D> = {| ...$Exact<OP>, ...SP, dispatch: D |};73 declare type MergeOPDP<OP, DP> = {| ...$Exact<OP>, ...DP |};74 declare type MergeOPSPDP<OP, SP, DP> = {| ...$Exact<OP>, ...SP, ...DP |};75 declare export function connect<-P, -OP, -SP, -DP, -S, -D>(76 mapStateToProps?: null | void,77 mapDispatchToProps?: null | void,78 mergeProps?: null | void,79 options?: ?Options<S, OP, {||}, MergeOP<OP, D>>,80 ): Connector<P, OP, MergeOP<OP, D>>;81 declare export function connect<-P, -OP, -SP, -DP, -S, -D>(82 // If you get error here try adding return type to your mapStateToProps function83 mapStateToProps: MapStateToProps<S, OP, SP>,84 mapDispatchToProps?: null | void,85 mergeProps?: null | void,86 options?: ?Options<S, OP, SP, MergeOPSP<OP, SP, D>>,87 ): Connector<P, OP, MergeOPSP<OP, SP, D>>;88 // In this case DP is an object of functions which has been bound to dispatch89 // by the given mapDispatchToProps function.90 declare export function connect<-P, -OP, -SP, -DP, S, D>(91 mapStateToProps: null | void,92 mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,93 mergeProps?: null | void,94 options?: ?Options<S, OP, {||}, MergeOPDP<OP, DP>>,95 ): Connector<P, OP, MergeOPDP<OP, DP>>;96 // In this case DP is an object of action creators not yet bound to dispatch,97 // this difference is not important in the vanila redux,98 // but in case of usage with redux-thunk, the return type may differ.99 declare export function connect<-P, -OP, -SP, -DP, S, D>(100 mapStateToProps: null | void,101 mapDispatchToProps: DP,102 mergeProps?: null | void,103 options?: ?Options<S, OP, {||}, MergeOPDP<OP, DP>>,104 ): Connector<P, OP, MergeOPDP<OP, $ObjMap<DP, Bind<D>>>>;105 declare export function connect<-P, -OP, -SP, -DP, S, D>(106 // If you get error here try adding return type to your mapStateToProps function107 mapStateToProps: MapStateToProps<S, OP, SP>,108 mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,109 mergeProps?: null | void,110 options?: ?Options<S, OP, SP, {| ...OP, ...SP, ...DP |}>,111 ): Connector<P, OP, {| ...OP, ...SP, ...DP |}>;112 declare export function connect<-P, -OP, -SP, -DP, S, D>(113 // If you get error here try adding return type to your mapStateToProps function114 mapStateToProps: MapStateToProps<S, OP, SP>,115 mapDispatchToProps: DP,116 mergeProps?: null | void,117 options?: ?Options<S, OP, SP, MergeOPSPDP<OP, SP, DP>>,118 ): Connector<P, OP, MergeOPSPDP<OP, SP, $ObjMap<DP, Bind<D>>>>;119 // With `mergeProps` argument120 declare type MergeProps<+P, -OP, -SP, -DP> = (121 stateProps: SP,122 dispatchProps: DP,123 ownProps: OP,124 ) => P;125 declare export function connect<-P, -OP, -SP: {||}, -DP: {||}, S, D>(126 mapStateToProps: null | void,127 mapDispatchToProps: null | void,128 // If you get error here try adding return type to you mapStateToProps function129 mergeProps: MergeProps<P, OP, {||}, {| dispatch: D |}>,130 options?: ?Options<S, OP, {||}, P>,131 ): Connector<P, OP, P>;132 declare export function connect<-P, -OP, -SP, -DP: {||}, S, D>(133 mapStateToProps: MapStateToProps<S, OP, SP>,134 mapDispatchToProps: null | void,135 // If you get error here try adding return type to you mapStateToProps function136 mergeProps: MergeProps<P, OP, SP, {| dispatch: D |}>,137 options?: ?Options<S, OP, SP, P>,138 ): Connector<P, OP, P>;139 // In this case DP is an object of functions which has been bound to dispatch140 // by the given mapDispatchToProps function.141 declare export function connect<-P, -OP, -SP: {||}, -DP, S, D>(142 mapStateToProps: null | void,143 mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,144 mergeProps: MergeProps<P, OP, {||}, DP>,145 options?: ?Options<S, OP, {||}, P>,146 ): Connector<P, OP, P>;147 // In this case DP is an object of action creators not yet bound to dispatch,148 // this difference is not important in the vanila redux,149 // but in case of usage with redux-thunk, the return type may differ.150 declare export function connect<-P, -OP, -SP: {||}, -DP, S, D>(151 mapStateToProps: null | void,152 mapDispatchToProps: DP,153 mergeProps: MergeProps<P, OP, {||}, $ObjMap<DP, Bind<D>>>,154 options?: ?Options<S, OP, {||}, P>,155 ): Connector<P, OP, P>;156 // In this case DP is an object of functions which has been bound to dispatch157 // by the given mapDispatchToProps function.158 declare export function connect<-P, -OP, -SP, -DP, S, D>(159 mapStateToProps: MapStateToProps<S, OP, SP>,160 mapDispatchToProps: MapDispatchToPropsFn<D, OP, DP>,161 mergeProps: MergeProps<P, OP, SP, DP>,162 options?: ?Options<S, OP, SP, P>,163 ): Connector<P, OP, P>;164 // In this case DP is an object of action creators not yet bound to dispatch,165 // this difference is not important in the vanila redux,166 // but in case of usage with redux-thunk, the return type may differ.167 declare export function connect<-P, -OP, -SP, -DP, S, D>(168 mapStateToProps: MapStateToProps<S, OP, SP>,169 mapDispatchToProps: DP,170 mergeProps: MergeProps<P, OP, SP, $ObjMap<DP, Bind<D>>>,171 options?: ?Options<S, OP, SP, P>,172 ): Connector<P, OP, P>;173 // ------------------------------------------------------------174 // Typings for Hooks175 // ------------------------------------------------------------176 declare export function useDispatch<D>(): D;177 declare export function useSelector<S, SS>(178 selector: (state: S) => SS,179 equalityFn?: (a: SS, b: SS) => boolean,180 ): SS;181 declare export function useStore<Store>(): Store;182 // ------------------------------------------------------------183 // Typings for Provider184 // ------------------------------------------------------------185 declare export class Provider<Store> extends React$Component<{186 store: Store,187 children?: React$Node,188 ...189 }> {}190 declare export function createProvider(191 storeKey?: string,192 subKey?: string,193 ): Class<Provider<*>>;194 // ------------------------------------------------------------195 // Typings for connectAdvanced()196 // ------------------------------------------------------------197 declare type ConnectAdvancedOptions = {198 getDisplayName?: (name: string) => string,199 methodName?: string,200 renderCountProp?: string,201 shouldHandleStateChanges?: boolean,202 storeKey?: string,203 forwardRef?: boolean,204 ...205 };206 declare type SelectorFactoryOptions<Com> = {207 getDisplayName: (name: string) => string,208 methodName: string,209 renderCountProp: ?string,210 shouldHandleStateChanges: boolean,211 storeKey: string,212 forwardRef: boolean,213 displayName: string,214 wrappedComponentName: string,215 WrappedComponent: Com,216 ...217 };218 declare type MapStateToPropsEx<S: Object, SP: Object, RSP: Object> = (219 state: S,220 props: SP,221 ) => RSP;222 declare type SelectorFactory<223 Com: React$ComponentType<*>,224 Dispatch,225 S: Object,226 OP: Object,227 EFO: Object,228 CP: Object,229 > = (230 dispatch: Dispatch,231 factoryOptions: SelectorFactoryOptions<Com> & EFO,232 ) => MapStateToPropsEx<S, OP, CP>;233 declare export function connectAdvanced<234 Com: React$ComponentType<*>,235 D,236 S: Object,237 OP: Object,238 CP: Object,239 EFO: Object,240 ST: { [_: $Keys<Com>]: any, ... },241 >(242 selectorFactory: SelectorFactory<Com, D, S, OP, EFO, CP>,243 connectAdvancedOptions: ?(ConnectAdvancedOptions & EFO),244 ): (component: Com) => React$ComponentType<OP> & $Shape<ST>;245 declare export function batch(() => void): void246 declare export default {247 Provider: typeof Provider,248 createProvider: typeof createProvider,249 connect: typeof connect,250 connectAdvanced: typeof connectAdvanced,251 useDispatch: typeof useDispatch,252 useSelector: typeof useSelector,253 useStore: typeof useStore,254 batch: typeof batch,255 ...256 };...
react-redux_v5.x.x.js
Source:react-redux_v5.x.x.js
1// flow-typed signature: 59b0c4be0e1408f21e2446be96c798042// flow-typed version: 9092387fd2/react-redux_v5.x.x/flow_>=v0.54.x3import type { Dispatch, Store } from "redux";4declare module "react-redux" {5 /*6 S = State7 A = Action8 OP = OwnProps9 SP = StateProps10 DP = DispatchProps11 */12 declare type MapStateToProps<S, OP: Object, SP: Object> = (13 state: S,14 ownProps: OP15 ) => ((state: S, ownProps: OP) => SP) | SP;16 declare type MapDispatchToProps<A, OP: Object, DP: Object> =17 | ((dispatch: Dispatch<A>, ownProps: OP) => DP)18 | DP;19 declare type MergeProps<SP, DP: Object, OP: Object, P: Object> = (20 stateProps: SP,21 dispatchProps: DP,22 ownProps: OP23 ) => P;24 declare type Context = { store: Store<*, *> };25 declare type ComponentWithDefaultProps<DP: {}, P: {}, CP: P> = Class<26 React$Component<CP>27 > & { defaultProps: DP };28 declare class ConnectedComponentWithDefaultProps<29 OP,30 DP,31 CP32 > extends React$Component<OP> {33 static defaultProps: DP, // <= workaround for https://github.com/facebook/flow/issues/464434 static WrappedComponent: Class<React$Component<CP>>,35 getWrappedInstance(): React$Component<CP>,36 props: OP,37 state: void38 }39 declare class ConnectedComponent<OP, P> extends React$Component<OP> {40 static WrappedComponent: Class<React$Component<P>>,41 getWrappedInstance(): React$Component<P>,42 props: OP,43 state: void44 }45 declare type ConnectedComponentWithDefaultPropsClass<OP, DP, CP> = Class<46 ConnectedComponentWithDefaultProps<OP, DP, CP>47 >;48 declare type ConnectedComponentClass<OP, P> = Class<49 ConnectedComponent<OP, P>50 >;51 declare type Connector<OP, P> = (<DP: {}, CP: {}>(52 component: ComponentWithDefaultProps<DP, P, CP>53 ) => ConnectedComponentWithDefaultPropsClass<OP, DP, CP>) &54 ((component: React$ComponentType<P>) => ConnectedComponentClass<OP, P>);55 declare class Provider<S, A> extends React$Component<{56 store: Store<S, A>,57 children?: any58 }> {}59 declare function createProvider(60 storeKey?: string,61 subKey?: string62 ): Provider<*, *>;63 declare type ConnectOptions = {64 pure?: boolean,65 withRef?: boolean66 };67 declare type Null = null | void;68 declare function connect<A, OP>(69 ...rest: Array<void> // <= workaround for https://github.com/facebook/flow/issues/236070 ): Connector<OP, $Supertype<{ dispatch: Dispatch<A> } & OP>>;71 declare function connect<A, OP>(72 mapStateToProps: Null,73 mapDispatchToProps: Null,74 mergeProps: Null,75 options: ConnectOptions76 ): Connector<OP, $Supertype<{ dispatch: Dispatch<A> } & OP>>;77 declare function connect<S, A, OP, SP>(78 mapStateToProps: MapStateToProps<S, OP, SP>,79 mapDispatchToProps: Null,80 mergeProps: Null,81 options?: ConnectOptions82 ): Connector<OP, $Supertype<SP & { dispatch: Dispatch<A> } & OP>>;83 declare function connect<A, OP, DP>(84 mapStateToProps: Null,85 mapDispatchToProps: MapDispatchToProps<A, OP, DP>,86 mergeProps: Null,87 options?: ConnectOptions88 ): Connector<OP, $Supertype<DP & OP>>;89 declare function connect<S, A, OP, SP, DP>(90 mapStateToProps: MapStateToProps<S, OP, SP>,91 mapDispatchToProps: MapDispatchToProps<A, OP, DP>,92 mergeProps: Null,93 options?: ConnectOptions94 ): Connector<OP, $Supertype<SP & DP & OP>>;95 declare function connect<S, A, OP, SP, DP, P>(96 mapStateToProps: MapStateToProps<S, OP, SP>,97 mapDispatchToProps: Null,98 mergeProps: MergeProps<SP, DP, OP, P>,99 options?: ConnectOptions100 ): Connector<OP, P>;101 declare function connect<S, A, OP, SP, DP, P>(102 mapStateToProps: MapStateToProps<S, OP, SP>,103 mapDispatchToProps: MapDispatchToProps<A, OP, DP>,104 mergeProps: MergeProps<SP, DP, OP, P>,105 options?: ConnectOptions106 ): Connector<OP, P>;...
test.js
Source:test.js
1const mergeProps = require('./index');2describe('merges special properties', () => {3 it('merges styles', () => {4 expect(mergeProps({5 style: { color: 'white' }6 }, {7 style: { backgroundColor: 'black' }8 })).toEqual({9 style: {10 color: 'white',11 backgroundColor: 'black'12 }13 });14 });15 it('merges class names', () => {16 expect(mergeProps({17 className: 'name1'18 }, {19 className: 'name2'20 })).toEqual({21 className: 'name1 name2'22 });23 });24 it('merges functions with prefix "on"', () => {25 const event1 = jest.fn();26 const event2 = jest.fn();27 const newEvent = mergeProps({28 onClick: event129 }, {30 onClick: event231 }).onClick;32 newEvent();33 expect(event1.mock.calls.length).toBe(1);34 expect(event2.mock.calls.length).toBe(1);35 });36});37describe('does not merge normal properties', () => {38 it('does not merge normal objects', () => {39 expect(mergeProps({40 styles: { color: 'red' }41 }, {42 styles: { textAlign: 'center' }43 })).toEqual({44 styles: { textAlign: 'center' }45 });46 });47 it('does not merge normal strings', () => {48 expect(mergeProps({49 namedClass: 'name1'50 }, {51 namedClass: 'name2'52 })).toEqual({53 namedClass: 'name2'54 });55 });56 it('does not merge normal functions', () => {57 const event1 = jest.fn();58 const event2 = jest.fn();59 const newEvent = mergeProps({60 offClick: event161 }, {62 offClick: event263 }).offClick;64 newEvent();65 expect(event1.mock.calls.length).toBe(0);66 expect(event2.mock.calls.length).toBe(1);67 });68});69describe('ignores children', () => {70 it('removes children field for any args', () => {71 expect(mergeProps({ children: '' }, { children: [] })).toEqual({});72 });73});74describe('returns values', () => {75 it('returns empty object for zero arguments', () => {76 expect(mergeProps()).toEqual({});77 });78 it("returns the first argument when it's the first argument", () => {79 const props = { onlyProp: 'onlyValue' };80 expect(mergeProps(props)).toBe(props);81 });82 it('returns the merged object for two arguments', () => {83 const obj1 = { key1: 'val1' };84 const obj2 = { key2: 'val2' };85 expect(mergeProps(obj1, obj2)).toEqual({86 key1: 'val1',87 key2: 'val2'88 });89 });90 it('returns the merged object for three arguments', () => {91 const obj1 = { key1: 'val1' };92 const obj2 = { key2: 'val2' };93 const obj3 = { key3: 'val3' };94 expect(mergeProps(obj1, obj2, obj3)).toEqual({95 key1: 'val1',96 key2: 'val2',97 key3: 'val3'98 });99 });100});101describe('on conflict', () => {102 it('returns non undefined item', () => {103 expect(mergeProps({104 className: 'name1 name2'105 }, {106 className: undefined107 })).toEqual({108 className: 'name1 name2'109 });110 expect(mergeProps({111 className: undefined112 }, {113 className: 'name3 name4'114 })).toEqual({115 className: 'name3 name4'116 });117 });118 it('the latter takes precedence', () => {119 expect(mergeProps({120 key1: 'val1'121 }, {122 key1: 'val2'123 })).toEqual({124 key1: 'val2'125 });126 });...
mergeProps.js
Source:mergeProps.js
...11 let hasRunOnce = false12 let mergedProps13 return function mergePropsProxy(stateProps, dispatchProps, ownProps) {14 // æ§è¡ mergeProps15 const nextMergedProps = mergeProps(stateProps, dispatchProps, ownProps)16 // åç»æ¯å¦éå¤æ´æ°(å¤æç»ææ¯å¦ç¸ç)17 if (hasRunOnce) {18 // åç»æ§è¡19 // épure æè
ä¸ç(æµ
æ¯è¾)ï¼æ´æ°æ°æ®20 if (!pure || !areMergedPropsEqual(nextMergedProps, mergedProps))21 mergedProps = nextMergedProps22 } else {23 // 第ä¸æ¬¡æ§è¡ ç´æ¥æ´æ°æ°æ®24 hasRunOnce = true25 mergedProps = nextMergedProps26 if (process.env.NODE_ENV !== 'production')27 verifyPlainObject(mergedProps, displayName, 'mergeProps')28 }29 return mergedProps...
actions.js
Source:actions.js
1import { CHANGE_VALUE, CHANGE_ERROR, VALIDATE_FORM, FORM_VALID } from './constants';2export function changeValue(e, mergeProps) {3 const nullMethod = () => {};4 (mergeProps.onchange || nullMethod)(e);5 const targetValue = e.target.value;6 const isCheckbox = ['checkbox', 'radio'].indexOf((mergeProps.type || '')) !== -1;7 const checkedValue = isCheckbox ? e.target.checked : targetValue;8 return {9 type: CHANGE_VALUE,10 id: mergeProps.id,11 form: mergeProps.form || 'default',12 validators: mergeProps.validators || [],13 value: (typeof targetValue === 'string' ? checkedValue : (mergeProps.value || '')),14 };15}16export function changeError(mergeProps, error) {17 return {18 type: CHANGE_ERROR,19 id: mergeProps.id,20 form: mergeProps.form || 'default',21 error,22 };23}24export function validateForm(form) {25 return {26 type: VALIDATE_FORM,27 form,28 };29}30export function formValid(form) {31 return {32 type: FORM_VALID,33 form,34 };...
config.js
Source:config.js
...8import * as params from '../../config/params.json';9import * as synth from '../../config/synth.json';10import * as ui from '../../config/ui.json';11import mergeProps from './mergeProps';12const buttons = mergeProps(_buttons);13const connectors = mergeProps(_connectors);14const knobs = mergeProps(_knobs);15const leds = mergeProps(_leds);16const screens = mergeProps(_screens);17const touchstrips = mergeProps(_touchstrips);18export {19 buttons,20 connectors,21 enums,22 knobs,23 leds,24 params,25 screens,26 synth,27 touchstrips,28 ui...
Using AI Code Generation
1const { chromium } = require('playwright');2(async () => {3 const browser = await chromium.launch();4 const context = await browser.newContext();5 const page = await context.newPage();6 await page.waitForTimeout(1000);7 await page.screenshot({ path: 'google.png' });8 await browser.close();9})();10 at CDPSession.send (C:\Users\user\Documents\Playwright\playwright\lib\protocol\cdpSession.js:139:19)11 at ExecutionContext._evaluateInternal (C:\Users\user\Documents\Playwright\playwright\lib\client\executionContext.js:91:50)12 at ExecutionContext.evaluate (C:\Users\user\Documents\Playwright\playwright\lib\client\executionContext.js:30:17)13 at Page.evaluate (C:\Users\user\Documents\Playwright\playwright\lib\client\page.js:111:33)14 at Page.mergeProps (C:\Users\user\Documents\Playwright\playwright\lib\client\page.js:166:25)15 at processTicksAndRejections (internal/process/task_queues.js:93:5)
Using AI Code Generation
1const { mergeProps } = require('playwright/lib/utils/utils');2const { chromium } = require('playwright');3(async () => {4 const browser = await chromium.launch();5 const page = await browser.newPage();6 const result = await page.evaluate(async () => {7 const { mergeProps } = require('playwright/lib/utils/utils');8 class Test {9 constructor() {10 this._options = {};11 }12 setOptions(options) {13 mergeProps(this._options, options);14 }15 getOptions() {16 return this._options;17 }18 }19 const test = new Test();20 test.setOptions({ a: 'a', b: 'b' });21 test.setOptions({ b: 'B', c: 'c' });22 return test.getOptions();23 });24 console.log(result);25 await browser.close();26})();27{ a: 'a', b: 'B', c: 'c' }28const { chromium } = require('playwright');29(async () => {30 const browser = await chromium.launch();31 const page = await browser.newPage();32 const result = await page.evaluate(async () => {33 const { mergeProps } = require('playwright/lib/utils/utils');34 class Test {35 constructor() {36 this._options = {};37 }38 setOptions(options) {39 mergeProps(this._options, options);40 }41 getOptions() {42 return this._options;43 }44 }45 const test = new Test();46 test.setOptions({ a: 'a', b: 'b' });47 test.setOptions({ b: 'B', c: 'c' });48 return test.getOptions();49 });50 console.log(result);51 await browser.close();52})();53{ a: 'a', b: 'B', c: 'c' }54const { chromium } = require('playwright');55(async () => {56 const browser = await chromium.launch();57 const page = await browser.newPage();58 const result = await page.evaluate(async () => {
Using AI Code Generation
1const { mergeProps } = require('playwright/lib/utils/utils');2const { chromium } = require('playwright');3const browser = await chromium.launch();4const context = await browser.newContext();5const page = await context.newPage();6const { pageProxy } = page;7const { _pageBindings } = pageProxy;8const { _pageBindingsMap } = _pageBindings;9const { _context } = pageProxy;10const { _browserContext } = _context;11const { _browser } = _browserContext;12const { _browserProcess } = _browser;13const { _process } = _browserProcess;14const { _options } = _process;15const { _logger } = _options;16const { _loggers } = _logger;17const { _consoleLogger } = _loggers;18const { _log } = _consoleLogger;19const { _logMethod } = _log;20const { _logFunction } = _logMethod;21const { _logFunctionImpl } = _logFunction;22const { _logFunctionImplWithPrefix } = _logFunctionImpl;23const { _logFunctionImplWithPrefixAndSource } = _logFunctionImplWithPrefix;24const { _logFunctionImplWithPrefixAndSourceAndTimestamp } = _logFunctionImplWithPrefixAndSource;25const { _logFunctionImplWithPrefixAndSourceAndTimestampAndColor } = _logFunctionImplWithPrefixAndSourceAndTimestamp;26const { _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTrace } = _logFunctionImplWithPrefixAndSourceAndTimestampAndColor;27const { _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTraceAndTestInfo } = _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTrace;28const { _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTraceAndTestInfoAndLocation } = _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTraceAndTestInfo;29const { _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTraceAndTestInfoAndLocationAndBrowser } = _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTraceAndTestInfoAndLocation;30const { _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTraceAndTestInfoAndLocationAndBrowserAndBrowserContext } = _logFunctionImplWithPrefixAndSourceAndTimestampAndColorAndStackTraceAndTestInfoAndLocationAndBrowser;31const {
Using AI Code Generation
1const { chromium } = require('playwright');2const { mergeProps, mergeObjects } = require('playwright/lib/utils/utils');3(async () => {4 const browser = await chromium.launch();5 const context = await browser.newContext();6 const page = await context.newPage();7 const element = await page.$('text=Get started');8 const props = await element._client.send('DOM.describeNode', {9 });10 console.log(mergeProps(props.node));11 await browser.close();12})();13const { chromium } = require('playwright');14const { mergeProps, mergeObjects } = require('playwright/lib/utils/utils');15(async () => {16 const browser = await chromium.launch();17 const context = await browser.newContext();18 const page = await context.newPage();19 const element = await page.$('text=Get started');20 const props = await element._client.send('DOM.describeNode', {21 });22 console.log(mergeObjects(props.node));23 await browser.close();24})();25const { chromium } = require('playwright');26const { mergeProps, mergeObjects } = require('playwright/lib/utils/utils');27(async () => {28 const browser = await chromium.launch();29 const context = await browser.newContext();30 const page = await context.newPage();31 const element = await page.$('text=Get started');32 const props = await element._client.send('DOM.describeNode', {33 });34 console.log(mergeObjects(props.node));35 await browser.close();36})();37const { chromium } = require('playwright');38const { mergeProps, mergeObjects } = require('playwright/lib/utils/utils');39(async () => {40 const browser = await chromium.launch();41 const context = await browser.newContext();42 const page = await context.newPage();
Using AI Code Generation
1const {mergeProps} = require('playwright/lib/server/frames');2const frame = await page.mainFrame();3const result = await frame.evaluate(mergeProps, {a: 1, b: 2}, {a: 3, c: 4});4const {mergeProps} = require('playwright/lib/server/frames');5const frame = await page.mainFrame();6const result = await frame.evaluate(mergeProps, {a: 1, b: 2}, {a: 3, c: 4});7const {mergeProps} = require('playwright/lib/server/frames');8const frame = await page.mainFrame();9const result = await frame.evaluate(mergeProps, {a: 1, b: 2}, {a: 3, c: 4});10const {mergeProps} = require('playwright/lib/server/frames');11const frame = await page.mainFrame();12const result = await frame.evaluate(mergeProps, {a: 1, b: 2}, {a: 3, c: 4});13const {mergeProps} = require('playwright/lib/server/frames');14const frame = await page.mainFrame();15const result = await frame.evaluate(mergeProps, {a: 1, b: 2}, {a: 3, c: 4});16const {mergeProps} = require('playwright/lib/server/frames');
Using AI Code Generation
1const { mergeProps } = require("playwright/lib/server/dom.js");2const { parseSelectors } = require("playwright/lib/server/selectors.js");3const { Page } = require("playwright/lib/server/page.js");4const { ElementHandle } = require("playwright/lib/server/dom.js");5const { JSHandle } = require("playwright/lib/server/jsHandle.js");6const { CDPSession } = require("playwright/lib/cjs/puppeteer/common/Connection.js");7const page = new Page(new CDPSession(), new Map(), false);8const handle = new ElementHandle(page, null, null, null, null, null);9const jsHandle = new JSHandle(page, null, null, null, null, null);10const selector = "button";11const selectors = parseSelectors(selector);12const options = { timeout: 10000 };13const props = mergeProps(selectors, options);14console.log(props);15const { getAttribute } = require("playwright/lib/server/dom.js");16const { parseSelectors } = require("playwright/lib/server/selectors.js");17const { Page } = require("playwright/lib/server/page.js");18const { ElementHandle } = require("playwright/lib/server/dom.js");19const { JSHandle } = require("playwright/lib/server/jsHandle.js");20const { CDPSession } = require("playwright/lib/cjs/puppeteer/common/Connection.js");21const page = new Page(new CDPSession(), new Map(), false);22const handle = new ElementHandle(page, null, null, null, null, null);23const jsHandle = new JSHandle(page, null, null, null, null, null);24const selector = "button";25const selectors = parseSelectors(selector);26const options = { timeout: 10000 };27const props = mergeProps(selectors, options);28const attribute = "id";29const value = getAttribute(handle, jsHandle, attribute);30console.log(value);31const { getAttribute } = require("playwright/lib/server/dom.js");32const { parseSelectors } = require("playwright/lib/server/selectors.js");33const { Page } = require("playwright/lib/server/page.js");34const { ElementHandle } = require("playwright/lib/server/dom.js");35const { JSHandle } = require("playwright/lib/server/jsHandle.js");36const { CD
Using AI Code Generation
1const { mergeProps } = require('@playwright/test');2const { test } = require('@playwright/test');3test('merge props', async ({ page }) => {4 const props = {5 };6 const props2 = {7 };8 const mergedProps = mergeProps(props, props2);9 console.log(mergedProps);10});11const { mergeProps } = require('@playwright/test');12const { test } = require('@playwright/test');13test('merge props', async ({ page }) => {14 const props = {15 };16 const props2 = {17 };18 const mergedProps = mergeProps(props, props2);19 console.log(mergedProps);20});
Using AI Code Generation
1const { mergeProps } = require('@playwright/test/lib/utils/utils');2const test = require('@playwright/test');3const { devices } = require('./devices');4const devicesList = Object.keys(devices);5function createTestsForDevices(devices) {6 devices.forEach((device) => {7 test.describe(device, () => {8 test.beforeEach(async ({ page }) => {9 await page.emulate(devices[device]);10 });11 test('test', async ({ page }) => {12 const title = await page.title();13 test.expect(title).toBe('Playwright');14 });15 });16 });17}18const config = {19 use: {20 viewport: { width: 1280, height: 720 },21 },22 {23 use: {24 },25 },26 {27 use: {28 },29 },30 {31 use: {32 },33 },34 {35 use: mergeProps(devices['Pixel 5'], {36 }),37 },38 {39 use: mergeProps(devices['Pixel 5'], {40 }),41 },42};43createTestsForDevices(devicesList);44module.exports = config;45const devices = {46 'Pixel 5': {47 viewport: { width: 412, height: 869 },48 'Mozilla/5.0 (Linux; Android 11) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Mobile Safari/537.36',49 },50 'Pixel 2': {51 viewport: { width: 411, height: 731 },52 'Mozilla/5.0 (Linux; Android 10) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Mobile Safari/537.36',
LambdaTest’s Playwright tutorial will give you a broader idea about the Playwright automation framework, its unique features, and use cases with examples to exceed your understanding of Playwright testing. This tutorial will give A to Z guidance, from installing the Playwright framework to some best practices and advanced concepts.
Get 100 minutes of automation test minutes FREE!!