Best JavaScript code snippet using playwright-internal
index.spec.js
Source: index.spec.js
...31 props: { [key]: { type, required: true } },32 })(Component)33 it('checks arrays', () => {34 withRequired('array', array)(Cmp)35 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)36 expect(actual).toEqual(37 'Failed prop type: The prop `array` is marked as required in `Cmp`, but its value is `undefined`.',38 )39 })40 it('checks bools', () => {41 withRequired('bool', bool)(Cmp)42 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)43 expect(actual).toEqual(44 'Failed prop type: The prop `bool` is marked as required in `Cmp`, but its value is `undefined`.',45 )46 })47 it('checks funcs', () => {48 withRequired('func', func)(Cmp)49 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)50 expect(actual).toEqual(51 'Failed prop type: The prop `func` is marked as required in `Cmp`, but its value is `undefined`.',52 )53 })54 it('checks numbers', () => {55 withRequired('number', number)(Cmp)56 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)57 expect(actual).toEqual(58 'Failed prop type: The prop `number` is marked as required in `Cmp`, but its value is `undefined`.',59 )60 })61 it('checks objects', () => {62 withRequired('object', object)(Cmp)63 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)64 expect(actual).toEqual(65 'Failed prop type: The prop `object` is marked as required in `Cmp`, but its value is `undefined`.',66 )67 })68 it('checks strings', () => {69 withRequired('string', string)(Cmp)70 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)71 expect(actual).toEqual(72 'Failed prop type: The prop `string` is marked as required in `Cmp`, but its value is `undefined`.',73 )74 })75 it('checks symbols', () => {76 withRequired('symbol', symbol)(Cmp)77 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)78 expect(actual).toEqual(79 'Failed prop type: The prop `symbol` is marked as required in `Cmp`, but its value is `undefined`.',80 )81 })82 it('checks nodes', () => {83 withRequired('node', node)(Cmp)84 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)85 expect(actual).toEqual(86 'Failed prop type: The prop `node` is marked as required in `Cmp`, but its value is `undefined`.',87 )88 })89 it('checks elements', () => {90 withRequired('element', element)(Cmp)91 const actual = checkPropTypes(Cmp.propTypes, {}, LABEL, Cmp.name)92 expect(actual).toEqual(93 'Failed prop type: The prop `element` is marked as required in `Cmp`, but its value is `undefined`.',94 )95 })96 })97 describe('checks data type', () => {98 class TestInstance {}99 const Cmp = ({ children }) => children100 withPropDocs({101 name: 'Cmp',102 props: {103 array: { type: array },104 bool: { type: bool },105 func: { type: func },106 number: { type: number },107 object: { type: object },108 string: { type: string },109 symbol: { type: symbol },110 node: { type: node },111 element: { type: element },112 oneOf: { type: oneOf(['string', 0]) },113 oneOfType: { type: oneOfType([string]) },114 instanceOf: { type: instanceOf(TestInstance) },115 arrayOf: { type: arrayOf(string) },116 arrayOfShape: {117 type: arrayOf(118 shape({119 string: {120 type: string,121 },122 }).type,123 ),124 },125 objectOf: { type: objectOf(string) },126 },127 })(Cmp)128 console.log(Cmp.propInfo)129 const props = Cmp.propTypes130 const name = Cmp.name131 it('check array', () => {132 const actual = checkPropTypes(props, { array: '' }, LABEL, name)133 expect(actual).toEqual(134 'Failed prop type: Invalid prop `array` of type `string` supplied to `Cmp`, expected `array`.',135 )136 })137 it('checks booleans', () => {138 const actual = checkPropTypes(props, { bool: '' }, LABEL, name)139 expect(actual).toEqual(140 'Failed prop type: Invalid prop `bool` of type `string` supplied to `Cmp`, expected `boolean`.',141 )142 })143 it('checks functions', () => {144 const actual = checkPropTypes(props, { func: '' }, LABEL, name)145 expect(actual).toEqual(146 'Failed prop type: Invalid prop `func` of type `string` supplied to `Cmp`, expected `function`.',147 )148 })149 it('checks number', () => {150 const actual = checkPropTypes(props, { number: '' }, LABEL, name)151 expect(actual).toEqual(152 'Failed prop type: Invalid prop `number` of type `string` supplied to `Cmp`, expected `number`.',153 )154 })155 it('checks object', () => {156 const actual = checkPropTypes(props, { object: '' }, LABEL, name)157 expect(actual).toEqual(158 'Failed prop type: Invalid prop `object` of type `string` supplied to `Cmp`, expected `object`.',159 )160 })161 it('checks string', () => {162 const actual = checkPropTypes(props, { string: 123 }, LABEL, name)163 expect(actual).toEqual(164 'Failed prop type: Invalid prop `string` of type `number` supplied to `Cmp`, expected `string`.',165 )166 })167 it('checks symbol', () => {168 const actual = checkPropTypes(props, { symbol: '' }, LABEL, name)169 expect(actual).toEqual(170 'Failed prop type: Invalid prop `symbol` of type `string` supplied to `Cmp`, expected `symbol`.',171 )172 })173 // it('checks node', () => {174 // it('checks data type', () => {175 // const actual = checkPropTypes(props, { node: '' }, LABEL, name)176 // const expected = invalidType(name, 'node', 'node', 'string')177 //178 // expect(actual).toEqual(expected)179 // })180 // })181 it('checks element', () => {182 const actual = checkPropTypes(props, { element: '' }, LABEL, name)183 expect(actual).toEqual(184 'Failed prop type: Invalid prop `element` of type `string` supplied to `Cmp`, expected a single ReactElement.',185 )186 })187 it('checks oneOf', () => {188 const actual = checkPropTypes(props, { oneOf: '' }, LABEL, name)189 expect(actual).toEqual(190 'Failed prop type: Invalid prop `oneOf` of value `` supplied to `Cmp`, expected one of ["string",0].',191 )192 })193 it('checks oneOfType', () => {194 const actual = checkPropTypes(props, { oneOfType: 123 }, LABEL, name)195 expect(actual).toEqual(196 'Failed prop type: Invalid prop `oneOfType` supplied to `Cmp`.',197 )198 })199 it('checks arrayOf', () => {200 const actual = checkPropTypes(props, { arrayOf: '' }, LABEL, name)201 expect(actual).toEqual(202 'Failed prop type: Invalid prop `arrayOf` of type `string` supplied to `Cmp`, expected an array.',203 )204 })205 it('checks arrayOfShape', () => {206 const actual = checkPropTypes(props, { arrayOfShape: '' }, LABEL, name)207 expect(actual).toEqual(208 'Failed prop type: Invalid prop `arrayOfShape` of type `string` supplied to `Cmp`, expected an array.',209 )210 })211 it('checks instanceOf', () => {212 const actual = checkPropTypes(props, { instanceOf: '' }, LABEL, name)213 expect(actual).toEqual(214 'Failed prop type: Invalid prop `instanceOf` of type `String` supplied to `Cmp`, expected instance of `TestInstance`.',215 )216 })217 })218 describe('checks shape', () => {219 const Cmp = ({ children }) => children220 withPropDocs({221 name: 'Cmp',222 props: {223 shape: shape({224 string: {225 type: string,226 },227 shape: shape({228 string: {229 type: string,230 },231 }),232 }),233 },234 })(Cmp)235 const props = Cmp.propTypes236 const defaults = Cmp.defaultProps237 const name = Cmp.name238 it('checks data type', () => {239 const actual = checkPropTypes(240 props,241 {242 shape:243 'Failed prop type: Invalid prop `shape.string` of type `number` supplied to `Cmp`, expected `string`.',244 },245 LABEL,246 name,247 )248 expect(actual).toEqual(249 'Failed prop type: Invalid prop `shape` of type `string` supplied to `Cmp`, expected `object`.',250 )251 })252 it('checks keys', () => {253 const actual = checkPropTypes(254 props,255 { shape: { string: 123 } },256 LABEL,257 name,258 )259 expect(actual).toEqual(260 'Failed prop type: Invalid prop `shape.string` of type `number` supplied to `Cmp`, expected `string`.',261 )262 })263 it('checks nested shape', () => {264 const actual = checkPropTypes(265 props,266 {267 shape: {268 shape: {269 string: 123,270 },271 },272 },273 LABEL,274 name,275 )276 expect(actual).toEqual(277 'Failed prop type: Invalid prop `shape.shape.string` of type `number` supplied to `Cmp`, expected `string`.',278 )...
songList.test.js
Source: songList.test.js
...133 const props01 = { recieved: 4, tracks: [] }134 const props00 = { recieved: 4, tracks: {} }135 //testing with full props136 it('should not throw a warning', () => {137 const result = checkPropTypes(SongList.propTypes, { ...fullProps }, 'prop', SongList.name);138 expect(result).toBeUndefined();139 })140 //testing pause function by sending invalid data141 it('should throw a warning', () => {142 const result = checkPropTypes(SongList.propTypes, { pause: '1' }, 'prop', SongList.name);143 expect(result).toBeDefined();144 })145 it('should throw a warning', () => {146 const result = checkPropTypes(SongList.propTypes, { pause: 1 }, 'prop', SongList.name);147 expect(result).toBeDefined();148 })149 it('should throw a warning', () => {150 const result = checkPropTypes(SongList.propTypes, { pause: true }, 'prop', SongList.name);151 expect(result).toBeDefined();152 })153 //testing resume function by sending invalid data154 it('should throw a warning', () => {155 const result = checkPropTypes(SongList.propTypes, { resume: '1' }, 'prop', SongList.name);156 expect(result).toBeDefined();157 })158 it('should throw a warning', () => {159 const result = checkPropTypes(SongList.propTypes, { resume: 1 }, 'prop', SongList.name);160 expect(result).toBeDefined();161 })162 it('should throw a warning', () => {163 const result = checkPropTypes(SongList.propTypes, { resume: true }, 'prop', SongList.name);164 expect(result).toBeDefined();165 })166 //testing addToQueue function by sending invalid data167 it('should throw a warning', () => {168 const result = checkPropTypes(SongList.propTypes, { addToQueue: '1' }, 'prop', SongList.name);169 expect(result).toBeDefined();170 })171 it('should throw a warning', () => {172 const result = checkPropTypes(SongList.propTypes, { addToQueue: 1 }, 'prop', SongList.name);173 expect(result).toBeDefined();174 })175 it('should throw a warning', () => {176 const result = checkPropTypes(SongList.propTypes, { addToQueue: true }, 'prop', SongList.name);177 expect(result).toBeDefined();178 })179 //testing clicked Item Id by sending false data180 it('should not throw a warning', () => {181 const result = checkPropTypes(SongList.propTypes, { clickedItemId: 1 }, 'prop', SongList.name);182 expect(result).toBeDefined();183 });184 it('should not throw a warning', () => {185 const result = checkPropTypes(SongList.propTypes, props11, 'prop', SongList.name);186 expect(result).toBeUndefined();187 });188 it('should throw a warning', () => {189 const result = checkPropTypes(SongList.propTypes, props10, 'prop', SongList.name);190 expect(result).toBeDefined();191 });192 it('should not throw a warning', () => {193 const result = checkPropTypes(SongList.propTypes, props01, 'prop', SongList.name);194 expect(result).toBeDefined();195 });196 it('should throw a warning', () => {197 const result = checkPropTypes(SongList.propTypes, props00, 'prop', SongList.name);198 expect(result).toBeDefined();199 });200 });201 describe('snapshot test', () => {202 it('renders correctly', () => {203 const tree = renderer204 .create(<SongList {...fullProps} />)205 .toJSON();206 expect(tree).toMatchSnapshot();207 });208 });...
types.test.js
Source: types.test.js
...26 publishableKey: 'publishableKey',27 merchantId: 'merchantId',28 androidPayMode: 'development'29 };30 t.doesNotThrow(checkPropTypes(setOptionsOptionsPropTypes, passedProps));31 t.end();32});33test('availableApplePayNetworkPropTypes', t => {34 const goodNetworks = availableApplePayNetworks;35 // Good cases36 goodNetworks.forEach(network => {37 t.doesNotThrow(38 checkPropTypes(39 { network: availableApplePayNetworkPropTypes },40 { network }41 ),42 `${network} is available ApplePay Network`43 );44 });45 // Bad cases46 const badNetworks = ['twitter', 'facebook', 'instagram', 'telegram'];47 badNetworks.forEach(network => {48 t.throws(49 checkPropTypes(50 { network: availableApplePayNetworkPropTypes },51 { network }52 ),53 `${network} should throws when check availableApplePayNetworks`54 );55 });56 t.end();57});58test('canMakeApplePayPaymentsOptionsPropTypes', t => {59 const passedProps = availableApplePayNetworks;60 t.doesNotThrow(61 checkPropTypes(canMakeApplePayPaymentsOptionsPropTypes, passedProps)62 );63 t.end();64});65test('paymentRequestWithApplePayItemPropTypes', t => {66 // Check bad value67 const badTypes = ['lol', 'kek'];68 badTypes.forEach(type => {69 const passedProps = {70 type,71 label: 'label',72 amount: 'amount'73 };74 t.throws(75 checkPropTypes(76 paymentRequestWithApplePayItemPropTypes,77 passedProps,78 'items',79 'Stripe.paymentRequestWithApplePay'80 ),81 `${type} should throws an error about bad type`82 );83 });84 const goodTypes = ['final', 'pending'];85 // Check typo oneOf('final', 'pending')86 goodTypes.forEach(type => {87 const passedProps = {88 type,89 label: 'label',90 amount: 'amount'91 };92 t.doesNotThrow(93 checkPropTypes(paymentRequestWithApplePayItemPropTypes, passedProps),94 'typeSpecs[typeSpecName] is not a function'95 );96 });97 t.end();98});99test('paymentRequestWithApplePayItemsPropTypes', t => {100 const types = ['final', 'pending'];101 types.forEach(type => {102 const passedProps = {103 items: [104 {105 type,106 label: 'label',107 amount: 'amount'108 }109 ]110 };111 t.doesNotThrow(112 checkPropTypes(paymentRequestWithApplePayItemsPropTypes, passedProps)113 );114 });115 t.end();116});117test('applePayAddressFieldsPropTypes', t => {118 const goodFields = availableApplePayAddressFields;119 // Good cases120 goodFields.forEach(field => {121 t.doesNotThrow(122 checkPropTypes({ field: applePayAddressFieldsPropTypes }, { field }),123 `${field} is available ApplePay address field`124 );125 });126 // Bad cases127 const badFields = ['home', 'flat', 'door', 'floor'];128 badFields.forEach(field => {129 t.throws(130 checkPropTypes({ field: applePayAddressFieldsPropTypes }, { field }),131 `${field} should throws when check availableApplePayAddressFields`132 );133 });134 t.end();135});136test('applePayOptionShippingMethodPropTypes', t => {137 const passedProps = {138 id: 'id',139 label: 'label',140 detail: 'detail',141 amount: 'amount'142 };143 t.doesNotThrow(144 checkPropTypes(applePayOptionShippingMethodPropTypes, passedProps)145 );146 t.end();147});148test('paymentRequestWithApplePayOptionsPropTypes', t => {149 availableApplePayShippingTypes.forEach(shippingType => {150 const passedProps = {151 currencyCode: 'currencyCode',152 countryCode: 'countryCode',153 requiredBillingAddressFields: availableApplePayAddressFields,154 requiredShippingAddressFields: availableApplePayAddressFields,155 shippingMethods: [156 {157 id: 'id',158 label: 'label',159 detail: 'detail',160 amount: 'amount'161 }162 ],163 shippingType164 };165 t.doesNotThrow(166 checkPropTypes(paymentRequestWithApplePayOptionsPropTypes, passedProps)167 );168 });169 t.end();170});171test('paymentRequestWithCardFormOptionsPropTypes', t => {172 const billingAddressFields = ['full', 'zip'];173 billingAddressFields.forEach(billingAddressField => {174 const passedProps = {175 requiredBillingAddressFields: billingAddressField,176 managedAccountCurrency: 'managedAccountCurrency',177 smsAutofillDisabled: true,178 prefilledInformation: {179 email: 'email',180 phone: 'phone',181 billingAddress: {182 name: 'name',183 line1: 'line1',184 line2: 'line2',185 city: 'city',186 state: 'state',187 postalCode: 'postalCode',188 country: 'country',189 phone: 'phone',190 email: 'email'191 }192 },193 theme: {194 primaryBackgroundColor: 'primaryBackgroundColor',195 secondaryBackgroundColor: 'secondaryBackgroundColor',196 primaryForegroundColor: 'primaryForegroundColor',197 secondaryForegroundColor: 'secondaryForegroundColor',198 accentColor: 'accentColor',199 errorColor: 'errorColor'200 }201 };202 t.doesNotThrow(203 checkPropTypes(paymentRequestWithCardFormOptionsPropTypes, passedProps)204 );205 });206 t.end();207});208test('createTokenWithCardParamsPropTypes', t => {209 const passedProps = {210 number: 'number',211 expMonth: 11,212 expYear: 20,213 cvc: 'cvc',214 name: 'name',215 addressLine1: 'addressLine1',216 addressLine2: 'addressLine2',217 addressCity: 'addressCity',218 addressState: 'addressState',219 addressZip: 'addressZip',220 addressCountry: 'addressCountry',221 country: 'country',222 currency: 'currency',223 // Android Only224 brand: 'brand',225 last4: 'last4',226 fingerprint: 'fingerprint',227 funding: 'funding'228 };229 t.doesNotThrow(230 checkPropTypes(createTokenWithCardParamsPropTypes, passedProps)231 );232 t.end();233});234test('createTokenWithBankAccountParamsPropTypes', t => {235 const accountHolderTypes = ['company', 'individual'];236 accountHolderTypes.forEach(accountHolderType => {237 const passedProps = {238 accountNumber: 'accountNumber',239 countryCode: 'countryCode',240 currency: 'currency',241 routingNumber: 'routingNumber',242 accountHolderName: 'accountHolderName',243 accountHolderType244 };245 t.doesNotThrow(246 checkPropTypes(createTokenWithBankAccountParamsPropTypes, passedProps)247 );248 });249 t.end();250});251test('androidPayLineItemPropTypes', t => {252 const passedProps = {253 currency_code: 'currency_code',254 total_price: 'total_price',255 unit_price: 'unit_price',256 quantity: 'quantity',257 description: 'description'258 };259 t.doesNotThrow(checkPropTypes(androidPayLineItemPropTypes, passedProps));260 t.end();261});262test('paymentRequestWithAndroidPayOptionsPropTypes', t => {263 const passedProps = {264 total_price: 'total_price',265 currency_code: 'currency_code',266 line_items: [267 {268 currency_code: 'currency_code',269 total_price: 'total_price',270 unit_price: 'unit_price',271 quantity: 'quantity',272 description: 'description'273 }274 ],275 shipping_address_required: false,276 billing_address_required: false277 };278 t.doesNotThrow(279 checkPropTypes(paymentRequestWithAndroidPayOptionsPropTypes, passedProps)280 );281 t.end();282});283test('createSourceWithParamsPropType', t => {284 availableSourceTypes.forEach(type => {285 const passedProps = {286 type,287 amount: 100,288 name: 'name',289 returnURL: 'returnURL',290 statementDescriptor: 'statementDescriptor',291 currency: 'currency',292 email: 'email',293 bank: 'bank',294 iban: 'iban',295 addressLine1: 'addressLine1',296 city: 'city',297 postalCode: 'postalCode',298 country: 'country',299 card: 'card'300 };301 t.doesNotThrow(checkPropTypes(createSourceWithParamsPropType, passedProps));302 });303 t.end();...
CheckPropTypes.test.js
Source: CheckPropTypes.test.js
1import { defaultCommandLayout } from "~commands";2import CheckPropTypes from "../index";3const onChange = jest.fn();4const value = "";5const children = <p>Previewer</p>;6const editorRef = jest.fn();7const initProps = {8 autoGrow: false,9 classes: {},10 children,11 commands: defaultCommandLayout,12 debounceSuggestions: 300,13 disableGrip: false,14 disableHotKeys: false,15 disablePreview: false,16 disableToolbar: false,17 hideGrip: false,18 editorRef,19 maxCharacterLength: null,20 maxEditorHeight: 600,21 maxEditorWidth: "100%",22 minEditorHeight: 300,23 onChange,24 readOnly: false,25 selectedTab: "write",26 showCharacterLength: false,27 suggestionTriggerCharacter: "@",28 textAreaProps: { placeholder: "What's on your mind?" },29 tooltipPlacement: "top",30 value,31};32describe("Check MDEditor PropTypes", () => {33 it("initially doesn't throw any errors", () => {34 expect(() => CheckPropTypes(initProps)).not.toThrow();35 });36 it("handles children type checks", () => {37 expect(() => CheckPropTypes({ ...initProps, children: undefined })).toThrow(38 "The MDEditor must include a Markdown previewer as a child!",39 );40 });41 it("handles value type checks", () => {42 expect(() => CheckPropTypes({ ...initProps, value: undefined })).toThrow(43 "The MDEditor must include a string value property!",44 );45 });46 it("handles onChange type checks", () => {47 expect(() => CheckPropTypes({ ...initProps, onChange: undefined })).toThrow(48 "The MDEditor must include an onChange function property!",49 );50 });51 it("handles selectedTab type checks", () => {52 expect(() =>53 CheckPropTypes({ ...initProps, selectedTab: undefined }),54 ).toThrow(55 "The MDEditor was initialized with an invalid 'selectedTab' property. It must be a string that is either 'write' or 'preview'!",56 );57 expect(() =>58 CheckPropTypes({ ...initProps, selectedTab: "badtab" }),59 ).toThrow(60 "The MDEditor was initialized with an invalid 'selectedTab' property. It must be a string that is either 'write' or 'preview'!",61 );62 expect(() =>63 CheckPropTypes({ ...initProps, selectedTab: "preview" }),64 ).not.toThrow();65 });66 it("handles autoGrow type checks", () => {67 expect(() => CheckPropTypes({ ...initProps, autoGrow: undefined })).toThrow(68 "The MDEditor was initialized with an invalid 'autoGrow' property. It must be a boolean!",69 );70 });71 it("handles classes type checks", () => {72 expect(() => CheckPropTypes({ ...initProps, classes: undefined })).toThrow(73 "The MDEditor was initialized with an invalid 'classes' property. It must be an object of strings!",74 );75 });76 it("handles commands type checks", () => {77 expect(() => CheckPropTypes({ ...initProps, commands: undefined })).toThrow(78 "The MDEditor was initialized with an invalid 'commands' property. It must be a single array of one or many arrays of grouped object commands!",79 );80 });81 it("handles debounceSuggestions type checks", () => {82 expect(() =>83 CheckPropTypes({ ...initProps, debounceSuggestions: undefined }),84 ).toThrow(85 "The MDEditor was initialized with an invalid 'debounceSuggestions' property. It must be a number!",86 );87 });88 it("handles disableGrip type checks", () => {89 expect(() =>90 CheckPropTypes({ ...initProps, disableGrip: undefined }),91 ).toThrow(92 "The MDEditor was initialized with an invalid 'disableGrip' property. It must be a boolean!",93 );94 });95 it("handles disableHotKeys type checks", () => {96 expect(() =>97 CheckPropTypes({ ...initProps, disableHotKeys: undefined }),98 ).toThrow(99 "The MDEditor was initialized with an invalid 'disableHotKeys' property. It must be a boolean!",100 );101 });102 it("handles disablePreview type checks", () => {103 expect(() =>104 CheckPropTypes({ ...initProps, disablePreview: undefined }),105 ).toThrow(106 "The MDEditor was initialized with an invalid 'disablePreview' property. It must be a boolean!",107 );108 });109 it("handles disableToolbar type checks", () => {110 expect(() =>111 CheckPropTypes({ ...initProps, disableToolbar: undefined }),112 ).toThrow(113 "The MDEditor was initialized with an invalid 'disableToolbar' property. It must be a boolean!",114 );115 });116 it("handles hideGrip type checks", () => {117 expect(() => CheckPropTypes({ ...initProps, hideGrip: undefined })).toThrow(118 "The MDEditor was initialized with an invalid 'hideGrip' property. It must be a boolean!",119 );120 });121 it("handles editorRef type checks", () => {122 expect(() =>123 CheckPropTypes({ ...initProps, editorRef: undefined }),124 ).toThrow(125 "The MDEditor was initialized with an invalid 'editorRef' property. It must be a callback function!",126 );127 });128 it("handles maxCharacterLength type checks", () => {129 expect(() =>130 CheckPropTypes({ ...initProps, maxCharacterLength: undefined }),131 ).toThrow(132 "The MDEditor was initialized with an invalid 'maxCharacterLength' property. It must be a number or string!",133 );134 });135 it("handles maxEditorHeight type checks", () => {136 expect(() =>137 CheckPropTypes({ ...initProps, maxEditorHeight: undefined }),138 ).toThrow(139 "The MDEditor was initialized with an invalid 'maxEditorHeight' property. It must be a number or string!",140 );141 });142 it("handles maxEditorWidth type checks", () => {143 expect(() =>144 CheckPropTypes({ ...initProps, maxEditorWidth: undefined }),145 ).toThrow(146 "The MDEditor was initialized with an invalid 'maxEditorWidth' property. It must be a number or string!",147 );148 });149 it("handles minEditorHeight type checks", () => {150 expect(() =>151 CheckPropTypes({ ...initProps, minEditorHeight: undefined }),152 ).toThrow(153 "The MDEditor was initialized with an invalid 'minEditorHeight' property. It must be a number or string!",154 );155 });156 it("handles readOnly type checks", () => {157 expect(() => CheckPropTypes({ ...initProps, readOnly: undefined })).toThrow(158 "The MDEditor was initialized with an invalid 'readOnly' property. It must be a boolean!",159 );160 });161 it("handles showCharacterLength type checks", () => {162 expect(() =>163 CheckPropTypes({ ...initProps, showCharacterLength: undefined }),164 ).toThrow(165 "The MDEditor was initialized with an invalid 'showCharacterLength' property. It must be a boolean!",166 );167 });168 it("handles suggestionTriggerCharacter type checks", () => {169 expect(() =>170 CheckPropTypes({ ...initProps, suggestionTriggerCharacter: undefined }),171 ).toThrow(172 "The MDEditor was initialized with an invalid 'suggestionTriggerCharacter' property. It must be a key string!",173 );174 });175 it("handles textAreaProps type checks", () => {176 expect(() =>177 CheckPropTypes({ ...initProps, textAreaProps: undefined }),178 ).toThrow(179 "The MDEditor was initialized with an invalid 'textAreaProps' property. It must be an object containing booleans, strings, numbers and/or functions!",180 );181 });182 it("handles tooltipPlacement type checks", () => {183 expect(() =>184 CheckPropTypes({ ...initProps, tooltipPlacement: undefined }),185 ).toThrow(186 "The MDEditor was initialized with an invalid 'tooltipPlacement' property. It must be a string containing one of the following: 'top','topLeft','topRight','bottom','bottomLeft','bottomRight','left','leftTop','leftBottom','right','rightTop' or'rightBottom'!",187 );188 });...
SearchAfterTyping.test.js
Source: SearchAfterTyping.test.js
...74 });75 });76 describe('testing prop types', () => {77 it('should pass true props', () => {78 const result = checkPropTypes(SearchAfterTyping.propTypes, { ...item }, 'prop', SearchAfterTyping.name);79 expect(result).toBeUndefined();80 });81 it('should pass false props', () => {82 const result = checkPropTypes(SearchAfterTyping.propTypes, { search: 0 }, 'prop', SearchAfterTyping.name);83 expect(result).toBeDefined();84 });85 it('should pass false props', () => {86 const result = checkPropTypes(SearchAfterTyping.propTypes, { search: true }, 'prop', SearchAfterTyping.name);87 expect(result).toBeDefined();88 });89 it('should pass false props', () => {90 const result = checkPropTypes(SearchAfterTyping.propTypes, { search: jest.fn }, 'prop', SearchAfterTyping.name);91 expect(result).toBeDefined();92 });93 it('should pass false props', () => {94 const result = checkPropTypes(SearchAfterTyping.propTypes, { search: [15] }, 'prop', SearchAfterTyping.name);95 expect(result).toBeDefined();96 });97 it('should pass false props', () => {98 const result = checkPropTypes(SearchAfterTyping.propTypes, { search: {} }, 'prop', SearchAfterTyping.name);99 expect(result).toBeDefined();100 });101 it('should pass false props', () => {102 const result = checkPropTypes(SearchAfterTyping.propTypes, { canSend: 0 }, 'prop', SearchAfterTyping.name);103 expect(result).toBeDefined();104 });105 it('should pass false props', () => {106 const result = checkPropTypes(SearchAfterTyping.propTypes, { canSend: "" }, 'prop', SearchAfterTyping.name);107 expect(result).toBeDefined();108 });109 it('should pass false props', () => {110 const result = checkPropTypes(SearchAfterTyping.propTypes, { canSend: jest.fn }, 'prop', SearchAfterTyping.name);111 expect(result).toBeDefined();112 });113 it('should pass false props', () => {114 const result = checkPropTypes(SearchAfterTyping.propTypes, { canSend: [15] }, 'prop', SearchAfterTyping.name);115 expect(result).toBeDefined();116 });117 it('should pass false props', () => {118 const result = checkPropTypes(SearchAfterTyping.propTypes, { canSend: {} }, 'prop', SearchAfterTyping.name);119 expect(result).toBeDefined();120 });121 })...
React-test.js
Source: React-test.js
1/**2 * Copyright 2013-present, Facebook, Inc.3 * All rights reserved.4 *5 * This source code is licensed under the BSD-style license found in the6 * LICENSE file in the root directory of this source tree. An additional grant7 * of patent rights can be found in the PATENTS file in the same directory.8 *9 * @emails react-core10 */11'use strict';12describe('React', () => {13 var React;14 beforeEach(() => {15 React = require('react');16 });17 it('should log a deprecation warning once when using React.createMixin', () => {18 spyOn(console, 'error');19 React.createMixin();20 React.createMixin();21 expectDev(console.error.calls.count()).toBe(1);22 expectDev(console.error.calls.argsFor(0)[0]).toContain(23 'React.createMixin is deprecated and should not be used',24 );25 });26 it('should warn once when attempting to access React.createClass', () => {27 spyOn(console, 'error');28 let createClass = React.createClass;29 createClass = React.createClass;30 expect(createClass).not.toBe(undefined);31 expectDev(console.error.calls.count()).toBe(1);32 expectDev(console.error.calls.argsFor(0)[0]).toContain(33 'React.createClass is no longer supported. Use a plain JavaScript ' +34 "class instead. If you're not yet ready to migrate, " +35 'create-react-class is available on npm as a drop-in replacement. ' +36 '(https://fb.me/migrating-from-react-create-class)',37 );38 });39 it('should warn once when attempting to access React.PropTypes', () => {40 spyOn(console, 'error');41 let PropTypes = React.PropTypes;42 PropTypes = React.PropTypes;43 expect(PropTypes).not.toBe(undefined);44 expectDev(console.error.calls.count()).toBe(1);45 expectDev(console.error.calls.argsFor(0)[0]).toContain(46 'PropTypes has been moved to a separate package. ' +47 'Accessing React.PropTypes is no longer supported ' +48 'and will be removed completely in React 16. ' +49 'Use the prop-types package on npm instead. ' +50 '(https://fb.me/migrating-from-react-proptypes)',51 );52 });53 it('should warn once when attempting to access React.checkPropTypes', () => {54 spyOn(console, 'error');55 let checkPropTypes = React.checkPropTypes;56 checkPropTypes = React.checkPropTypes;57 expect(checkPropTypes).not.toBe(undefined);58 expectDev(console.error.calls.count()).toBe(1);59 expectDev(console.error.calls.argsFor(0)[0]).toContain(60 'checkPropTypes has been moved to a separate package. ' +61 'Accessing React.checkPropTypes is no longer supported ' +62 'and will be removed completely in React 16. ' +63 'Use the prop-types package on npm instead. ' +64 '(https://fb.me/migrating-from-react-proptypes)',65 );66 });...
test.js
Source: test.js
2const PropTypes = require('prop-types');3const checkPropTypes = require('.');4test('Good props check falsy', function(assert) {5 assert.plan(2);6 assert.ifError(checkPropTypes({}, {}, 'prop'));7 assert.ifError(checkPropTypes({x: PropTypes.number}, {x: 1}, 'prop'));8});9test('Specifically, good props check undefined (#1)', function(assert) {10 assert.plan(3);11 assert.is(checkPropTypes({}, {}, 'prop'),12 undefined);13 assert.is(checkPropTypes({x: PropTypes.number}, {x: 1}, 'prop'),14 undefined);15 assert.isNot(checkPropTypes({}, {}, 'prop'),16 null);17});18test('Bad props return a message', function(assert) {19 assert.plan(1);20 var message = checkPropTypes({x: PropTypes.number}, {x: ''}, 'prop', 'C');21 assert.equal(message, 'Failed prop type: Invalid prop `x` of type `string` supplied to `C`, expected `number`.');22});23test('Bad propTypes fail check', function(assert) {24 assert.plan(2);25 var message;26 message = checkPropTypes({x: null}, {}, 'prop', 'C');27 assert.equal(message, 'C: prop type `x` is invalid; it must be a function, usually from React.PropTypes.');28 message = checkPropTypes({x: function() {return 1}}, {}, 'prop', 'C');29 assert.equal(message, 'C: type specification of prop `x` is invalid; the type checker function must return `null` or an `Error` but returned a number. You may have forgotten to pass an argument to the type checker creator (arrayOf, instanceOf, objectOf, oneOf, oneOfType, and shape all require an argument).');30});31test('Throwing propTypes fail check', function(assert) {32 assert.plan(1);33 function throwingType() {34 throw new Error('sup');35 }36 var message = checkPropTypes({x: throwingType}, {}, 'prop', 'C');37 assert.equal(message, 'Failed prop type: sup');38});39test('Does not avoid failing the same problem multiple times', function(assert) {40 assert.plan(2);41 assert.true(checkPropTypes({x: PropTypes.string}, {x: 1}, 'prop'));42 assert.true(checkPropTypes({x: PropTypes.string}, {x: 1}, 'prop'));43});44test('assertPropTypes throws instead of returning error', function(assert) {45 var assertPropTypes = checkPropTypes.assertPropTypes;46 assert.plan(2);47 assert.doesNotThrow(function() {48 assertPropTypes({x: PropTypes.number}, {x: 1}, 'prop', 'c');49 });50 assert.throws(function() {51 assertPropTypes({x: PropTypes.number}, {x: ''}, 'prop', 'c');52 });...
checkPropTypes.js
Source: checkPropTypes.js
1/* @flow */2import { PropTypes, checkPropTypes } from "react";3checkPropTypes({ foo: PropTypes.string }, { foo: 'foo' }, 'value', 'TestComponent'); // OK4checkPropTypes({ foo: PropTypes.string }, { foo: 'foo' }); // error: missing arguments5checkPropTypes({ foo: PropTypes.string }, { foo: 'foo' }, 'value'); // error: missing argument6checkPropTypes({ bar: PropTypes.string }, { foo: 'foo' }, 'value', 'TestComponent'); // error: property not found7checkPropTypes({ foo: PropTypes.string }, { foo: 'foo' }, 'value', 'TestComponent', () => 123); // error: number ~> string8checkPropTypes({ foo: PropTypes.string }, { foo: 'foo' }, 'value', 'TestComponent', () => null); // OK...
Using AI Code Generation
1const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');2const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');3const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');4const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');5const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');6const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');7const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');8const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');9const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');10const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');11const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');12const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');13const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');14const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');15const { checkPropTypes } = require('playwright/lib/server/supplements/utils/stackTrace');16const {
Using AI Code Generation
1const { checkPropTypes } = require('playwright/lib/server/common/utils');2const { checkPropTypes } = require('playwright/lib/server/common/utils');3const { checkPropTypes } = require('playwright/lib/server/common/utils');4const { checkPropTypes } = require('playwright/lib/server/common/utils');5const { checkPropTypes } = require('playwright/lib/server/common/utils');6const { checkPropTypes } = require('playwright/lib/server/common/utils');7const { checkPropTypes } = require('playwright/lib/server/common/utils');8const { checkPropTypes } = require('playwright/lib/server/common/utils');9const { checkPropTypes } = require('playwright/lib/server/common/utils');10const { checkPropTypes } = require('playwright/lib/server/common/utils');11const { checkPropTypes } = require('playwright/lib/server/common/utils');12const { checkPropTypes } = require('playwright/lib/server/common/utils');13const { checkPropTypes } = require('playwright/lib/server/common/utils');14const { checkPropTypes } = require('playwright/lib/server/common/utils');15const { checkPropTypes } = require('playwright/lib/server/common/utils');16const { checkPropTypes } = require('playwright/lib/server/common/utils');
Using AI Code Generation
1const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');2const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');3const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');4const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');5const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');6const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');7const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');8const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');9const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');10const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');11const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');12const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');13const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');14const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');15const { checkPropTypes } = require('@playwright/test/lib/server/trace/common/validate.js');16const {
Using AI Code Generation
1const { checkPropTypes } = require('playwright/lib/server/supplements/utils/utils');2const { Page } = require('playwright/lib/server/page');3const { helper } = require('playwright/lib/helper');4const page = new Page(null, null, null, null);5const { error } = checkPropTypes(page, 'Page', {6}, {7 foo: { type: 'string' },8});9console.log(error.message);10helper.releaseAll();
Using AI Code Generation
1const { checkPropTypes } = require('playwright/lib/utils/utils');2const { expect } = require('chai');3describe('Test', () => {4 it('should pass', () => {5 expect(checkPropTypes({ name: 'string' }, { name: 'John' }, 'prop')).to.be.undefined;6 });7});8const { checkPropTypes } = require('playwright/lib/utils/utils');9const { expect } = require('chai');10describe('Test', () => {11 it('should pass', () => {12 expect(checkPropTypes({ name: 'string' }, { name: 'John' }, 'prop')).to.be.undefined;13 });14});15const { checkPropTypes } = require('playwright/lib/utils/utils');16const { expect } = require('chai');17describe('Test', () => {18 it('should pass', () => {19 expect(checkPropTypes({ name: 'string' }, { name: 'John' }, 'prop')).to.be.undefined;20 });21});22const { checkPropTypes } = require('playwright/lib/utils/utils');23const { expect } = require('chai');24describe('Test', () => {25 it('should pass', () => {26 expect(checkPropTypes({ name: 'string' }, { name: 'John' }, 'prop')).to.be.undefined;27 });28});29const { checkPropTypes } = require('playwright/lib/utils/utils');30const { expect } = require('chai');31describe('Test', () => {32 it('should pass', () => {33 expect(checkPropTypes({ name: 'string' }, { name: 'John' }, 'prop')).to.be.undefined;34 });35});36const { checkPropTypes } = require('playwright/lib/utils/utils');37const { expect }
Using AI Code Generation
1const { checkPropTypes } = require('@playwright/test/lib/utils').internal;2const { expect } = require('@playwright/test');3const propType = require('./propType');4const { checkPropTypes } = require('@playwright/test/lib/utils').internal;5const { expect } = require('@playwright/test');6const propType = require('./propType');7test('should check prop types', async () => {8 const props = {9 };10 const result = checkPropTypes(propType, props, 'props', 'MyComponent');11 expect(result).toBeUndefined();12});13import PropTypes from 'prop-types';14const propType = {15};16export default propType;
Using AI Code Generation
1const { checkPropTypes } = require('playwright');2const { expect } = require('chai');3const { Page } = require('playwright');4const page = new Page();5const propTypes = {6};7const person = {8 address: {9 },10};11const result = checkPropTypes(propTypes, person, 'person', 'test');12expect(result).to.be.undefined;13console.log('No errors');14Your name to display (optional):15Your name to display (optional):
Using AI Code Generation
1const checkPropTypes = require('prop-types/checkPropTypes');2const { expect } = require('@playwright/test');3const {getConsoleMessage} = require('../utils/testUtils');4test('should log an error message when a prop type is invalid', async ({ page }) => {5 await page.click('text=Log In');6 await page.click('text=Log In');7 const consoleMessage = getConsoleMessage(page);8 const result = checkPropTypes(9 { name: PropTypes.string },10 { name: 123 },11 );12 expect(consoleMessage).toBe(13 'Warning: Failed prop type: Invalid prop `name` of type `number` supplied to `MyComponent`, expected `string`.\n in MyComponent (at App.js:27)\n in div (at App.js:26)\n in App (at src/index.js:7)'14 );15 expect(result).toBe(undefined);16});17const getConsoleMessage = async (page) => {18 const messages = [];19 page.on('console', (message) => {20 messages.push(message.text());21 });22 return messages.length > 0 ? messages[0] : null;23};24module.exports = { getConsoleMessage };25"scripts": {26 },
Jest + Playwright - Test callbacks of event-based DOM library
firefox browser does not start in playwright
Is it possible to get the selector from a locator object in playwright?
How to run a list of test suites in a single file concurrently in jest?
Running Playwright in Azure Function
firefox browser does not start in playwright
This question is quite close to a "need more focus" question. But let's try to give it some focus:
Does Playwright has access to the cPicker object on the page? Does it has access to the window object?
Yes, you can access both cPicker and the window object inside an evaluate call.
Should I trigger the events from the HTML file itself, and in the callbacks, print in the DOM the result, in some dummy-element, and then infer from that dummy element text that the callbacks fired?
Exactly, or you can assign values to a javascript variable:
const cPicker = new ColorPicker({
onClickOutside(e){
},
onInput(color){
window['color'] = color;
},
onChange(color){
window['result'] = color;
}
})
And then
it('Should call all callbacks with correct arguments', async() => {
await page.goto(`http://localhost:5000/tests/visual/basic.html`, {waitUntil:'load'})
// Wait until the next frame
await page.evaluate(() => new Promise(requestAnimationFrame))
// Act
// Assert
const result = await page.evaluate(() => window['color']);
// Check the value
})
Check out the latest blogs from LambdaTest on this topic:
Native apps are developed specifically for one platform. Hence they are fast and deliver superior performance. They can be downloaded from various app stores and are not accessible through browsers.
One of the essential parts when performing automated UI testing, whether using Selenium or another framework, is identifying the correct web elements the tests will interact with. However, if the web elements are not located correctly, you might get NoSuchElementException in Selenium. This would cause a false negative result because we won’t get to the actual functionality check. Instead, our test will fail simply because it failed to interact with the correct element.
Smartphones have changed the way humans interact with technology. Be it travel, fitness, lifestyle, video games, or even services, it’s all just a few touches away (quite literally so). We only need to look at the growing throngs of smartphone or tablet users vs. desktop users to grasp this reality.
As part of one of my consulting efforts, I worked with a mid-sized company that was looking to move toward a more agile manner of developing software. As with any shift in work style, there is some bewilderment and, for some, considerable anxiety. People are being challenged to leave their comfort zones and embrace a continuously changing, dynamic working environment. And, dare I say it, testing may be the most ‘disturbed’ of the software roles in agile development.
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!!