Best JavaScript code snippet using storybook-test-runner
matchers.js
Source:matchers.js
1'use strict';2Object.defineProperty(exports, '__esModule', {3 value: true4});5var _jestDiff = require('jest-diff');6var _jestDiff2 = _interopRequireDefault(_jestDiff);7var _jestGetType = require('jest-get-type');8var _jestGetType2 = _interopRequireDefault(_jestGetType);9var _jestRegexUtil = require('jest-regex-util');10var _jestMatcherUtils = require('jest-matcher-utils');11var _utils = require('./utils');12var _jasmine_utils = require('./jasmine_utils');13function _interopRequireDefault(obj) {14 return obj && obj.__esModule ? obj : {default: obj};15}16const matchers = {17 toBe: function(received, expected) {18 const comment = 'Object.is equality';19 const pass = Object.is(received, expected);20 const message = pass21 ? () =>22 (0, _jestMatcherUtils.matcherHint)('.toBe', undefined, undefined, {23 comment: comment,24 isNot: true25 }) +26 '\n\n' +27 `Expected: ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +28 `Received: ${(0, _jestMatcherUtils.printReceived)(received)}`29 : () => {30 const suggestToEqual =31 (0, _jestGetType2.default)(received) ===32 (0, _jestGetType2.default)(expected) &&33 ((0, _jestGetType2.default)(received) === 'object' ||34 (0, _jestGetType2.default)(expected) === 'array') &&35 (0, _jasmine_utils.equals)(received, expected, [36 _utils.iterableEquality37 ]);38 const oneline = (0, _utils.isOneline)(expected, received);39 const diffString = (0, _jestDiff2.default)(expected, received, {40 expand: this.expand41 });42 return (43 (0, _jestMatcherUtils.matcherHint)('.toBe', undefined, undefined, {44 comment: comment,45 isNot: false46 }) +47 '\n\n' +48 `Expected: ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +49 `Received: ${(0, _jestMatcherUtils.printReceived)(received)}` +50 (diffString && !oneline ? `\n\nDifference:\n\n${diffString}` : '') +51 (suggestToEqual ? ` ${_jestMatcherUtils.SUGGEST_TO_EQUAL}` : '')52 );53 };54 // Passing the the actual and expected objects so that a custom reporter55 // could access them, for example in order to display a custom visual diff,56 // or create a different error message57 return {58 actual: received,59 expected: expected,60 message: message,61 name: 'toBe',62 pass: pass63 };64 },65 toBeCloseTo: function(actual, expected) {66 let precision =67 arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;68 const secondArgument = arguments.length === 3 ? 'precision' : null;69 (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeCloseTo');70 const pass = Math.abs(expected - actual) < Math.pow(10, -precision) / 2;71 const message = () =>72 (0, _jestMatcherUtils.matcherHint)('.toBeCloseTo', undefined, undefined, {73 isNot: this.isNot,74 secondArgument: secondArgument75 }) +76 '\n\n' +77 `Precision: ${(0, _jestMatcherUtils.printExpected)(precision)}-digit\n` +78 `Expected: ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +79 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;80 return {message: message, pass: pass};81 },82 toBeDefined: function(actual, expected) {83 (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeDefined');84 const pass = actual !== void 0;85 const message = () =>86 (0, _jestMatcherUtils.matcherHint)('.toBeDefined', 'received', '', {87 isNot: this.isNot88 }) +89 '\n\n' +90 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;91 return {message: message, pass: pass};92 },93 toBeFalsy: function(actual, expected) {94 (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeFalsy');95 const pass = !actual;96 const message = () =>97 (0, _jestMatcherUtils.matcherHint)('.toBeFalsy', 'received', '', {98 isNot: this.isNot99 }) +100 '\n\n' +101 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;102 return {message: message, pass: pass};103 },104 toBeGreaterThan: function(actual, expected) {105 (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeGreaterThan');106 const pass = actual > expected;107 const message = () =>108 (0, _jestMatcherUtils.matcherHint)(109 '.toBeGreaterThan',110 undefined,111 undefined,112 {113 isNot: this.isNot114 }115 ) +116 '\n\n' +117 `Expected: ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +118 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;119 return {message: message, pass: pass};120 },121 toBeGreaterThanOrEqual: function(actual, expected) {122 (0, _jestMatcherUtils.ensureNumbers)(123 actual,124 expected,125 '.toBeGreaterThanOrEqual'126 );127 const pass = actual >= expected;128 const message = () =>129 (0, _jestMatcherUtils.matcherHint)(130 '.toBeGreaterThanOrEqual',131 undefined,132 undefined,133 {134 isNot: this.isNot135 }136 ) +137 '\n\n' +138 `Expected: ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +139 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;140 return {message: message, pass: pass};141 },142 toBeInstanceOf: function(received, constructor) {143 const constType = (0, _jestGetType2.default)(constructor);144 if (constType !== 'function') {145 throw new Error(146 (0, _jestMatcherUtils.matcherHint)(147 '.toBeInstanceOf',148 'value',149 'constructor',150 {151 isNot: this.isNot152 }153 ) +154 `\n\n` +155 `Expected constructor to be a function. Instead got:\n` +156 ` ${(0, _jestMatcherUtils.printExpected)(constType)}`157 );158 }159 const pass = received instanceof constructor;160 const message = pass161 ? () =>162 (0, _jestMatcherUtils.matcherHint)(163 '.toBeInstanceOf',164 'value',165 'constructor',166 {167 isNot: this.isNot168 }169 ) +170 '\n\n' +171 `Expected constructor: ${(0, _jestMatcherUtils.EXPECTED_COLOR)(172 constructor.name || String(constructor)173 )}\n` +174 `Received value: ${(0, _jestMatcherUtils.printReceived)(received)}`175 : () =>176 (0, _jestMatcherUtils.matcherHint)(177 '.toBeInstanceOf',178 'value',179 'constructor',180 {181 isNot: this.isNot182 }183 ) +184 '\n\n' +185 `Expected constructor: ${(0, _jestMatcherUtils.EXPECTED_COLOR)(186 constructor.name || String(constructor)187 )}\n` +188 `Received constructor: ${(0, _jestMatcherUtils.RECEIVED_COLOR)(189 received != null190 ? received.constructor && received.constructor.name191 : ''192 )}\n` +193 `Received value: ${(0, _jestMatcherUtils.printReceived)(received)}`;194 return {message: message, pass: pass};195 },196 toBeLessThan: function(actual, expected) {197 (0, _jestMatcherUtils.ensureNumbers)(actual, expected, '.toBeLessThan');198 const pass = actual < expected;199 const message = () =>200 (0, _jestMatcherUtils.matcherHint)(201 '.toBeLessThan',202 undefined,203 undefined,204 {205 isNot: this.isNot206 }207 ) +208 '\n\n' +209 `Expected: ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +210 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;211 return {message: message, pass: pass};212 },213 toBeLessThanOrEqual: function(actual, expected) {214 (0, _jestMatcherUtils.ensureNumbers)(215 actual,216 expected,217 '.toBeLessThanOrEqual'218 );219 const pass = actual <= expected;220 const message = () =>221 (0, _jestMatcherUtils.matcherHint)(222 '.toBeLessThanOrEqual',223 undefined,224 undefined,225 {226 isNot: this.isNot227 }228 ) +229 '\n\n' +230 `Expected: ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +231 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;232 return {message: message, pass: pass};233 },234 toBeNaN: function(actual, expected) {235 (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeNaN');236 const pass = Number.isNaN(actual);237 const message = () =>238 (0, _jestMatcherUtils.matcherHint)('.toBeNaN', 'received', '', {239 isNot: this.isNot240 }) +241 '\n\n' +242 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;243 return {message: message, pass: pass};244 },245 toBeNull: function(actual, expected) {246 (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeNull');247 const pass = actual === null;248 const message = () =>249 (0, _jestMatcherUtils.matcherHint)('.toBeNull', 'received', '', {250 isNot: this.isNot251 }) +252 '\n\n' +253 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;254 return {message: message, pass: pass};255 },256 toBeTruthy: function(actual, expected) {257 (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeTruthy');258 const pass = !!actual;259 const message = () =>260 (0, _jestMatcherUtils.matcherHint)('.toBeTruthy', 'received', '', {261 isNot: this.isNot262 }) +263 '\n\n' +264 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;265 return {message: message, pass: pass};266 },267 toBeUndefined: function(actual, expected) {268 (0, _jestMatcherUtils.ensureNoExpected)(expected, '.toBeUndefined');269 const pass = actual === void 0;270 const message = () =>271 (0, _jestMatcherUtils.matcherHint)('.toBeUndefined', 'received', '', {272 isNot: this.isNot273 }) +274 '\n\n' +275 `Received: ${(0, _jestMatcherUtils.printReceived)(actual)}`;276 return {message: message, pass: pass};277 },278 toContain: function(collection, value) {279 const collectionType = (0, _jestGetType2.default)(collection);280 let converted = null;281 if (Array.isArray(collection) || typeof collection === 'string') {282 // strings have `indexOf` so we don't need to convert283 // arrays have `indexOf` and we don't want to make a copy284 converted = collection;285 } else {286 try {287 converted = Array.from(collection);288 } catch (e) {289 throw new Error(290 (0, _jestMatcherUtils.matcherHint)(291 '[.not].toContainEqual',292 'collection',293 'value'294 ) +295 '\n\n' +296 `Expected ${(0, _jestMatcherUtils.RECEIVED_COLOR)(297 'collection'298 )} to be an array-like structure.\n` +299 (0, _jestMatcherUtils.printWithType)(300 'Received',301 collection,302 _jestMatcherUtils.printReceived303 )304 );305 }306 }307 // At this point, we're either a string or an Array,308 // which was converted from an array-like structure.309 const pass = converted.indexOf(value) != -1;310 const message = pass311 ? () =>312 (0, _jestMatcherUtils.matcherHint)(313 '.not.toContain',314 collectionType,315 'value'316 ) +317 '\n\n' +318 `Expected ${collectionType}:\n` +319 ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` +320 `Not to contain value:\n` +321 ` ${(0, _jestMatcherUtils.printExpected)(value)}\n`322 : () => {323 const suggestToContainEqual =324 converted !== null &&325 typeof converted !== 'string' &&326 converted instanceof Array &&327 converted.findIndex(item =>328 (0, _jasmine_utils.equals)(item, value, [_utils.iterableEquality])329 ) !== -1;330 return (331 (0, _jestMatcherUtils.matcherHint)(332 '.toContain',333 collectionType,334 'value'335 ) +336 '\n\n' +337 `Expected ${collectionType}:\n` +338 ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` +339 `To contain value:\n` +340 ` ${(0, _jestMatcherUtils.printExpected)(value)}` +341 (suggestToContainEqual342 ? `\n\n${_jestMatcherUtils.SUGGEST_TO_CONTAIN_EQUAL}`343 : '')344 );345 };346 return {message: message, pass: pass};347 },348 toContainEqual: function(collection, value) {349 const collectionType = (0, _jestGetType2.default)(collection);350 let converted = null;351 if (Array.isArray(collection)) {352 converted = collection;353 } else {354 try {355 converted = Array.from(collection);356 } catch (e) {357 throw new Error(358 (0, _jestMatcherUtils.matcherHint)(359 '[.not].toContainEqual',360 'collection',361 'value'362 ) +363 '\n\n' +364 `Expected ${(0, _jestMatcherUtils.RECEIVED_COLOR)(365 'collection'366 )} to be an array-like structure.\n` +367 (0, _jestMatcherUtils.printWithType)(368 'Received',369 collection,370 _jestMatcherUtils.printReceived371 )372 );373 }374 }375 const pass =376 converted.findIndex(item =>377 (0, _jasmine_utils.equals)(item, value, [_utils.iterableEquality])378 ) !== -1;379 const message = pass380 ? () =>381 (0, _jestMatcherUtils.matcherHint)(382 '.not.toContainEqual',383 collectionType,384 'value'385 ) +386 '\n\n' +387 `Expected ${collectionType}:\n` +388 ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` +389 `Not to contain a value equal to:\n` +390 ` ${(0, _jestMatcherUtils.printExpected)(value)}\n`391 : () =>392 (0, _jestMatcherUtils.matcherHint)(393 '.toContainEqual',394 collectionType,395 'value'396 ) +397 '\n\n' +398 `Expected ${collectionType}:\n` +399 ` ${(0, _jestMatcherUtils.printReceived)(collection)}\n` +400 `To contain a value equal to:\n` +401 ` ${(0, _jestMatcherUtils.printExpected)(value)}`;402 return {message: message, pass: pass};403 },404 toEqual: function(received, expected) {405 const pass = (0, _jasmine_utils.equals)(received, expected, [406 _utils.iterableEquality407 ]);408 const message = pass409 ? () =>410 (0, _jestMatcherUtils.matcherHint)('.not.toEqual') +411 '\n\n' +412 `Expected value to not equal:\n` +413 ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +414 `Received:\n` +415 ` ${(0, _jestMatcherUtils.printReceived)(received)}`416 : () => {417 const oneline = (0, _utils.isOneline)(expected, received);418 const diffString = (0, _jestDiff2.default)(expected, received, {419 expand: this.expand420 });421 return (422 (0, _jestMatcherUtils.matcherHint)('.toEqual') +423 '\n\n' +424 `Expected value to equal:\n` +425 ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +426 `Received:\n` +427 ` ${(0, _jestMatcherUtils.printReceived)(received)}` +428 (diffString && !oneline ? `\n\nDifference:\n\n${diffString}` : '')429 );430 };431 // Passing the the actual and expected objects so that a custom reporter432 // could access them, for example in order to display a custom visual diff,433 // or create a different error message434 return {435 actual: received,436 expected: expected,437 message: message,438 name: 'toEqual',439 pass: pass440 };441 },442 toHaveLength: function(received, length) {443 if (444 typeof received !== 'string' &&445 (!received || typeof received.length !== 'number')446 ) {447 throw new Error(448 (0, _jestMatcherUtils.matcherHint)(449 '[.not].toHaveLength',450 'received',451 'length'452 ) +453 '\n\n' +454 `Expected value to have a 'length' property that is a number. ` +455 `Received:\n` +456 ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` +457 (received458 ? `received.length:\n ${(0, _jestMatcherUtils.printReceived)(459 received.length460 )}`461 : '')462 );463 }464 const pass = received.length === length;465 const message = pass466 ? () =>467 (0, _jestMatcherUtils.matcherHint)(468 '.not.toHaveLength',469 'received',470 'length'471 ) +472 '\n\n' +473 `Expected value to not have length:\n` +474 ` ${(0, _jestMatcherUtils.printExpected)(length)}\n` +475 `Received:\n` +476 ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` +477 `received.length:\n` +478 ` ${(0, _jestMatcherUtils.printReceived)(received.length)}`479 : () =>480 (0, _jestMatcherUtils.matcherHint)(481 '.toHaveLength',482 'received',483 'length'484 ) +485 '\n\n' +486 `Expected value to have length:\n` +487 ` ${(0, _jestMatcherUtils.printExpected)(length)}\n` +488 `Received:\n` +489 ` ${(0, _jestMatcherUtils.printReceived)(received)}\n` +490 `received.length:\n` +491 ` ${(0, _jestMatcherUtils.printReceived)(received.length)}`;492 return {message: message, pass: pass};493 },494 toHaveProperty: function(object, keyPath, value) {495 const valuePassed = arguments.length === 3;496 const secondArgument = valuePassed ? 'value' : null;497 if (!object && typeof object !== 'string' && typeof object !== 'number') {498 throw new Error(499 (0, _jestMatcherUtils.matcherHint)(500 '[.not].toHaveProperty',501 'object',502 'path',503 {504 secondArgument: secondArgument505 }506 ) +507 '\n\n' +508 `Expected ${(0, _jestMatcherUtils.RECEIVED_COLOR)(509 'object'510 )} to be an object. Received:\n` +511 ` ${(0, _jestGetType2.default)(object)}: ${(0,512 _jestMatcherUtils.printReceived)(object)}`513 );514 }515 const keyPathType = (0, _jestGetType2.default)(keyPath);516 if (keyPathType !== 'string' && keyPathType !== 'array') {517 throw new Error(518 (0, _jestMatcherUtils.matcherHint)(519 '[.not].toHaveProperty',520 'object',521 'path',522 {523 secondArgument: secondArgument524 }525 ) +526 '\n\n' +527 `Expected ${(0, _jestMatcherUtils.EXPECTED_COLOR)(528 'path'529 )} to be a string or an array. Received:\n` +530 ` ${(0, _jestGetType2.default)(keyPath)}: ${(0,531 _jestMatcherUtils.printReceived)(keyPath)}`532 );533 }534 const result = (0, _utils.getPath)(object, keyPath);535 const lastTraversedObject = result.lastTraversedObject,536 hasEndProp = result.hasEndProp;537 const pass = valuePassed538 ? (0, _jasmine_utils.equals)(result.value, value, [539 _utils.iterableEquality540 ])541 : hasEndProp;542 const traversedPath = result.traversedPath.join('.');543 const message = pass544 ? () =>545 (0, _jestMatcherUtils.matcherHint)(546 '.not.toHaveProperty',547 'object',548 'path',549 {550 secondArgument: secondArgument551 }552 ) +553 '\n\n' +554 `Expected the object:\n` +555 ` ${(0, _jestMatcherUtils.printReceived)(object)}\n` +556 `Not to have a nested property:\n` +557 ` ${(0, _jestMatcherUtils.printExpected)(keyPath)}\n` +558 (valuePassed559 ? `With a value of:\n ${(0, _jestMatcherUtils.printExpected)(560 value561 )}\n`562 : '')563 : () => {564 const diffString =565 valuePassed && hasEndProp566 ? (0, _jestDiff2.default)(value, result.value, {567 expand: this.expand568 })569 : '';570 return (571 (0, _jestMatcherUtils.matcherHint)(572 '.toHaveProperty',573 'object',574 'path',575 {576 secondArgument: secondArgument577 }578 ) +579 '\n\n' +580 `Expected the object:\n` +581 ` ${(0, _jestMatcherUtils.printReceived)(object)}\n` +582 `To have a nested property:\n` +583 ` ${(0, _jestMatcherUtils.printExpected)(keyPath)}\n` +584 (valuePassed585 ? `With a value of:\n ${(0, _jestMatcherUtils.printExpected)(586 value587 )}\n`588 : '') +589 (hasEndProp590 ? `Received:\n` +591 ` ${(0, _jestMatcherUtils.printReceived)(result.value)}` +592 (diffString ? `\n\nDifference:\n\n${diffString}` : '')593 : traversedPath594 ? `Received:\n ${(0, _jestMatcherUtils.RECEIVED_COLOR)(595 'object'596 )}.${traversedPath}: ${(0, _jestMatcherUtils.printReceived)(597 lastTraversedObject598 )}`599 : '')600 );601 };602 if (pass === undefined) {603 throw new Error('pass must be initialized');604 }605 return {message: message, pass: pass};606 },607 toMatch: function(received, expected) {608 if (typeof received !== 'string') {609 throw new Error(610 (0, _jestMatcherUtils.matcherHint)(611 '[.not].toMatch',612 'string',613 'expected'614 ) +615 '\n\n' +616 `${(0, _jestMatcherUtils.RECEIVED_COLOR)(617 'string'618 )} value must be a string.\n` +619 (0, _jestMatcherUtils.printWithType)(620 'Received',621 received,622 _jestMatcherUtils.printReceived623 )624 );625 }626 if (627 !(expected && typeof expected.test === 'function') &&628 !(typeof expected === 'string')629 ) {630 throw new Error(631 (0, _jestMatcherUtils.matcherHint)(632 '[.not].toMatch',633 'string',634 'expected'635 ) +636 '\n\n' +637 `${(0, _jestMatcherUtils.EXPECTED_COLOR)(638 'expected'639 )} value must be a string or a regular expression.\n` +640 (0, _jestMatcherUtils.printWithType)(641 'Expected',642 expected,643 _jestMatcherUtils.printExpected644 )645 );646 }647 const pass = new RegExp(648 typeof expected === 'string'649 ? (0, _jestRegexUtil.escapeStrForRegex)(expected)650 : expected651 ).test(received);652 const message = pass653 ? () =>654 (0, _jestMatcherUtils.matcherHint)('.not.toMatch') +655 `\n\nExpected value not to match:\n` +656 ` ${(0, _jestMatcherUtils.printExpected)(expected)}` +657 `\nReceived:\n` +658 ` ${(0, _jestMatcherUtils.printReceived)(received)}`659 : () =>660 (0, _jestMatcherUtils.matcherHint)('.toMatch') +661 `\n\nExpected value to match:\n` +662 ` ${(0, _jestMatcherUtils.printExpected)(expected)}` +663 `\nReceived:\n` +664 ` ${(0, _jestMatcherUtils.printReceived)(received)}`;665 return {message: message, pass: pass};666 },667 toMatchObject: function(receivedObject, expectedObject) {668 if (typeof receivedObject !== 'object' || receivedObject === null) {669 throw new Error(670 (0, _jestMatcherUtils.matcherHint)(671 '[.not].toMatchObject',672 'object',673 'expected'674 ) +675 '\n\n' +676 `${(0, _jestMatcherUtils.RECEIVED_COLOR)(677 'received'678 )} value must be an object.\n` +679 (0, _jestMatcherUtils.printWithType)(680 'Received',681 receivedObject,682 _jestMatcherUtils.printReceived683 )684 );685 }686 if (typeof expectedObject !== 'object' || expectedObject === null) {687 throw new Error(688 (0, _jestMatcherUtils.matcherHint)(689 '[.not].toMatchObject',690 'object',691 'expected'692 ) +693 '\n\n' +694 `${(0, _jestMatcherUtils.EXPECTED_COLOR)(695 'expected'696 )} value must be an object.\n` +697 (0, _jestMatcherUtils.printWithType)(698 'Expected',699 expectedObject,700 _jestMatcherUtils.printExpected701 )702 );703 }704 const pass = (0, _jasmine_utils.equals)(receivedObject, expectedObject, [705 _utils.iterableEquality,706 _utils.subsetEquality707 ]);708 const message = pass709 ? () =>710 (0, _jestMatcherUtils.matcherHint)('.not.toMatchObject') +711 `\n\nExpected value not to match object:\n` +712 ` ${(0, _jestMatcherUtils.printExpected)(expectedObject)}` +713 `\nReceived:\n` +714 ` ${(0, _jestMatcherUtils.printReceived)(receivedObject)}`715 : () => {716 const diffString = (0, _jestDiff2.default)(717 expectedObject,718 (0, _utils.getObjectSubset)(receivedObject, expectedObject),719 {720 expand: this.expand721 }722 );723 return (724 (0, _jestMatcherUtils.matcherHint)('.toMatchObject') +725 `\n\nExpected value to match object:\n` +726 ` ${(0, _jestMatcherUtils.printExpected)(expectedObject)}` +727 `\nReceived:\n` +728 ` ${(0, _jestMatcherUtils.printReceived)(receivedObject)}` +729 (diffString ? `\nDifference:\n${diffString}` : '')730 );731 };732 return {message: message, pass: pass};733 },734 toStrictEqual: function(received, expected) {735 const pass = (0, _jasmine_utils.equals)(736 received,737 expected,738 [_utils.iterableEquality, _utils.typeEquality],739 true740 );741 const message = pass742 ? () =>743 (0, _jestMatcherUtils.matcherHint)('.not.toStrictEqual') +744 '\n\n' +745 `Expected value to not equal:\n` +746 ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +747 `Received:\n` +748 ` ${(0, _jestMatcherUtils.printReceived)(received)}`749 : () => {750 const diffString = (0, _jestDiff2.default)(expected, received, {751 expand: this.expand752 });753 return (754 (0, _jestMatcherUtils.matcherHint)('.toStrictEqual') +755 '\n\n' +756 `Expected value to equal:\n` +757 ` ${(0, _jestMatcherUtils.printExpected)(expected)}\n` +758 `Received:\n` +759 ` ${(0, _jestMatcherUtils.printReceived)(received)}` +760 (diffString ? `\n\nDifference:\n\n${diffString}` : '')761 );762 };763 // Passing the the actual and expected objects so that a custom reporter764 // could access them, for example in order to display a custom visual diff,765 // or create a different error message766 return {767 actual: received,768 expected: expected,769 message: message,770 name: 'toStrictEqual',771 pass: pass772 };773 }774};775/**776 * Copyright (c) 2014-present, Facebook, Inc. All rights reserved.777 *778 * This source code is licensed under the MIT license found in the779 * LICENSE file in the root directory of this source tree.780 *781 *782 */...
eslint-plugin-jest_vx.x.x.js
Source:eslint-plugin-jest_vx.x.x.js
1// flow-typed signature: 6f6ab619699b88513028c100f2528e4b2// flow-typed version: <<STUB>>/eslint-plugin-jest_v^22.3.0/flow_v0.62.03/**4 * This is an autogenerated libdef stub for:5 *6 * 'eslint-plugin-jest'7 *8 * Fill this stub out by replacing all the `any` types.9 *10 * Once filled out, we encourage you to share your work with the11 * community by sending a pull request to:12 * https://github.com/flowtype/flow-typed13 */14declare module 'eslint-plugin-jest' {15 declare module.exports: any;16}17/**18 * We include stubs for each file inside this npm package in case you need to19 * require those files directly. Feel free to delete any files that aren't20 * needed.21 */22declare module 'eslint-plugin-jest/processors/__tests__/snapshot-processor.test' {23 declare module.exports: any;24}25declare module 'eslint-plugin-jest/processors/snapshot-processor' {26 declare module.exports: any;27}28declare module 'eslint-plugin-jest/rules/__tests__/consistent-test-it.test' {29 declare module.exports: any;30}31declare module 'eslint-plugin-jest/rules/__tests__/expect-expect.test' {32 declare module.exports: any;33}34declare module 'eslint-plugin-jest/rules/__tests__/lowercase-name.test' {35 declare module.exports: any;36}37declare module 'eslint-plugin-jest/rules/__tests__/no-alias-methods.test' {38 declare module.exports: any;39}40declare module 'eslint-plugin-jest/rules/__tests__/no-disabled-tests.test' {41 declare module.exports: any;42}43declare module 'eslint-plugin-jest/rules/__tests__/no-focused-tests.test' {44 declare module.exports: any;45}46declare module 'eslint-plugin-jest/rules/__tests__/no-hooks.test' {47 declare module.exports: any;48}49declare module 'eslint-plugin-jest/rules/__tests__/no-identical-title.test' {50 declare module.exports: any;51}52declare module 'eslint-plugin-jest/rules/__tests__/no-jasmine-globals.test' {53 declare module.exports: any;54}55declare module 'eslint-plugin-jest/rules/__tests__/no-jest-import.test' {56 declare module.exports: any;57}58declare module 'eslint-plugin-jest/rules/__tests__/no-large-snapshots.test' {59 declare module.exports: any;60}61declare module 'eslint-plugin-jest/rules/__tests__/no-test-callback.test' {62 declare module.exports: any;63}64declare module 'eslint-plugin-jest/rules/__tests__/no-test-prefixes.test' {65 declare module.exports: any;66}67declare module 'eslint-plugin-jest/rules/__tests__/no-test-return-statement.test' {68 declare module.exports: any;69}70declare module 'eslint-plugin-jest/rules/__tests__/no-truthy-falsy.test' {71 declare module.exports: any;72}73declare module 'eslint-plugin-jest/rules/__tests__/prefer-called-with' {74 declare module.exports: any;75}76declare module 'eslint-plugin-jest/rules/__tests__/prefer-expect-assertions.test' {77 declare module.exports: any;78}79declare module 'eslint-plugin-jest/rules/__tests__/prefer-inline-snapshots.test' {80 declare module.exports: any;81}82declare module 'eslint-plugin-jest/rules/__tests__/prefer-spy-on.test' {83 declare module.exports: any;84}85declare module 'eslint-plugin-jest/rules/__tests__/prefer-strict-equal.test' {86 declare module.exports: any;87}88declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-be-null.test' {89 declare module.exports: any;90}91declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-be-undefined.test' {92 declare module.exports: any;93}94declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-contain.test' {95 declare module.exports: any;96}97declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-have-length.test' {98 declare module.exports: any;99}100declare module 'eslint-plugin-jest/rules/__tests__/prefer-todo.test' {101 declare module.exports: any;102}103declare module 'eslint-plugin-jest/rules/__tests__/require-tothrow-message.test' {104 declare module.exports: any;105}106declare module 'eslint-plugin-jest/rules/__tests__/valid-describe.test' {107 declare module.exports: any;108}109declare module 'eslint-plugin-jest/rules/__tests__/valid-expect-in-promise.test' {110 declare module.exports: any;111}112declare module 'eslint-plugin-jest/rules/__tests__/valid-expect.test' {113 declare module.exports: any;114}115declare module 'eslint-plugin-jest/rules/consistent-test-it' {116 declare module.exports: any;117}118declare module 'eslint-plugin-jest/rules/expect-expect' {119 declare module.exports: any;120}121declare module 'eslint-plugin-jest/rules/lowercase-name' {122 declare module.exports: any;123}124declare module 'eslint-plugin-jest/rules/no-alias-methods' {125 declare module.exports: any;126}127declare module 'eslint-plugin-jest/rules/no-disabled-tests' {128 declare module.exports: any;129}130declare module 'eslint-plugin-jest/rules/no-focused-tests' {131 declare module.exports: any;132}133declare module 'eslint-plugin-jest/rules/no-hooks' {134 declare module.exports: any;135}136declare module 'eslint-plugin-jest/rules/no-identical-title' {137 declare module.exports: any;138}139declare module 'eslint-plugin-jest/rules/no-jasmine-globals' {140 declare module.exports: any;141}142declare module 'eslint-plugin-jest/rules/no-jest-import' {143 declare module.exports: any;144}145declare module 'eslint-plugin-jest/rules/no-large-snapshots' {146 declare module.exports: any;147}148declare module 'eslint-plugin-jest/rules/no-test-callback' {149 declare module.exports: any;150}151declare module 'eslint-plugin-jest/rules/no-test-prefixes' {152 declare module.exports: any;153}154declare module 'eslint-plugin-jest/rules/no-test-return-statement' {155 declare module.exports: any;156}157declare module 'eslint-plugin-jest/rules/no-truthy-falsy' {158 declare module.exports: any;159}160declare module 'eslint-plugin-jest/rules/prefer-called-with' {161 declare module.exports: any;162}163declare module 'eslint-plugin-jest/rules/prefer-expect-assertions' {164 declare module.exports: any;165}166declare module 'eslint-plugin-jest/rules/prefer-inline-snapshots' {167 declare module.exports: any;168}169declare module 'eslint-plugin-jest/rules/prefer-spy-on' {170 declare module.exports: any;171}172declare module 'eslint-plugin-jest/rules/prefer-strict-equal' {173 declare module.exports: any;174}175declare module 'eslint-plugin-jest/rules/prefer-to-be-null' {176 declare module.exports: any;177}178declare module 'eslint-plugin-jest/rules/prefer-to-be-undefined' {179 declare module.exports: any;180}181declare module 'eslint-plugin-jest/rules/prefer-to-contain' {182 declare module.exports: any;183}184declare module 'eslint-plugin-jest/rules/prefer-to-have-length' {185 declare module.exports: any;186}187declare module 'eslint-plugin-jest/rules/prefer-todo' {188 declare module.exports: any;189}190declare module 'eslint-plugin-jest/rules/require-tothrow-message' {191 declare module.exports: any;192}193declare module 'eslint-plugin-jest/rules/util' {194 declare module.exports: any;195}196declare module 'eslint-plugin-jest/rules/valid-describe' {197 declare module.exports: any;198}199declare module 'eslint-plugin-jest/rules/valid-expect-in-promise' {200 declare module.exports: any;201}202declare module 'eslint-plugin-jest/rules/valid-expect' {203 declare module.exports: any;204}205// Filename aliases206declare module 'eslint-plugin-jest/index' {207 declare module.exports: $Exports<'eslint-plugin-jest'>;208}209declare module 'eslint-plugin-jest/index.js' {210 declare module.exports: $Exports<'eslint-plugin-jest'>;211}212declare module 'eslint-plugin-jest/processors/__tests__/snapshot-processor.test.js' {213 declare module.exports: $Exports<'eslint-plugin-jest/processors/__tests__/snapshot-processor.test'>;214}215declare module 'eslint-plugin-jest/processors/snapshot-processor.js' {216 declare module.exports: $Exports<'eslint-plugin-jest/processors/snapshot-processor'>;217}218declare module 'eslint-plugin-jest/rules/__tests__/consistent-test-it.test.js' {219 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/consistent-test-it.test'>;220}221declare module 'eslint-plugin-jest/rules/__tests__/expect-expect.test.js' {222 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/expect-expect.test'>;223}224declare module 'eslint-plugin-jest/rules/__tests__/lowercase-name.test.js' {225 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/lowercase-name.test'>;226}227declare module 'eslint-plugin-jest/rules/__tests__/no-alias-methods.test.js' {228 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-alias-methods.test'>;229}230declare module 'eslint-plugin-jest/rules/__tests__/no-disabled-tests.test.js' {231 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-disabled-tests.test'>;232}233declare module 'eslint-plugin-jest/rules/__tests__/no-focused-tests.test.js' {234 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-focused-tests.test'>;235}236declare module 'eslint-plugin-jest/rules/__tests__/no-hooks.test.js' {237 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-hooks.test'>;238}239declare module 'eslint-plugin-jest/rules/__tests__/no-identical-title.test.js' {240 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-identical-title.test'>;241}242declare module 'eslint-plugin-jest/rules/__tests__/no-jasmine-globals.test.js' {243 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-jasmine-globals.test'>;244}245declare module 'eslint-plugin-jest/rules/__tests__/no-jest-import.test.js' {246 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-jest-import.test'>;247}248declare module 'eslint-plugin-jest/rules/__tests__/no-large-snapshots.test.js' {249 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-large-snapshots.test'>;250}251declare module 'eslint-plugin-jest/rules/__tests__/no-test-callback.test.js' {252 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-test-callback.test'>;253}254declare module 'eslint-plugin-jest/rules/__tests__/no-test-prefixes.test.js' {255 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-test-prefixes.test'>;256}257declare module 'eslint-plugin-jest/rules/__tests__/no-test-return-statement.test.js' {258 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-test-return-statement.test'>;259}260declare module 'eslint-plugin-jest/rules/__tests__/no-truthy-falsy.test.js' {261 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/no-truthy-falsy.test'>;262}263declare module 'eslint-plugin-jest/rules/__tests__/prefer-called-with.js' {264 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-called-with'>;265}266declare module 'eslint-plugin-jest/rules/__tests__/prefer-expect-assertions.test.js' {267 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-expect-assertions.test'>;268}269declare module 'eslint-plugin-jest/rules/__tests__/prefer-inline-snapshots.test.js' {270 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-inline-snapshots.test'>;271}272declare module 'eslint-plugin-jest/rules/__tests__/prefer-spy-on.test.js' {273 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-spy-on.test'>;274}275declare module 'eslint-plugin-jest/rules/__tests__/prefer-strict-equal.test.js' {276 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-strict-equal.test'>;277}278declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-be-null.test.js' {279 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-to-be-null.test'>;280}281declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-be-undefined.test.js' {282 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-to-be-undefined.test'>;283}284declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-contain.test.js' {285 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-to-contain.test'>;286}287declare module 'eslint-plugin-jest/rules/__tests__/prefer-to-have-length.test.js' {288 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-to-have-length.test'>;289}290declare module 'eslint-plugin-jest/rules/__tests__/prefer-todo.test.js' {291 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/prefer-todo.test'>;292}293declare module 'eslint-plugin-jest/rules/__tests__/require-tothrow-message.test.js' {294 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/require-tothrow-message.test'>;295}296declare module 'eslint-plugin-jest/rules/__tests__/valid-describe.test.js' {297 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/valid-describe.test'>;298}299declare module 'eslint-plugin-jest/rules/__tests__/valid-expect-in-promise.test.js' {300 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/valid-expect-in-promise.test'>;301}302declare module 'eslint-plugin-jest/rules/__tests__/valid-expect.test.js' {303 declare module.exports: $Exports<'eslint-plugin-jest/rules/__tests__/valid-expect.test'>;304}305declare module 'eslint-plugin-jest/rules/consistent-test-it.js' {306 declare module.exports: $Exports<'eslint-plugin-jest/rules/consistent-test-it'>;307}308declare module 'eslint-plugin-jest/rules/expect-expect.js' {309 declare module.exports: $Exports<'eslint-plugin-jest/rules/expect-expect'>;310}311declare module 'eslint-plugin-jest/rules/lowercase-name.js' {312 declare module.exports: $Exports<'eslint-plugin-jest/rules/lowercase-name'>;313}314declare module 'eslint-plugin-jest/rules/no-alias-methods.js' {315 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-alias-methods'>;316}317declare module 'eslint-plugin-jest/rules/no-disabled-tests.js' {318 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-disabled-tests'>;319}320declare module 'eslint-plugin-jest/rules/no-focused-tests.js' {321 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-focused-tests'>;322}323declare module 'eslint-plugin-jest/rules/no-hooks.js' {324 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-hooks'>;325}326declare module 'eslint-plugin-jest/rules/no-identical-title.js' {327 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-identical-title'>;328}329declare module 'eslint-plugin-jest/rules/no-jasmine-globals.js' {330 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-jasmine-globals'>;331}332declare module 'eslint-plugin-jest/rules/no-jest-import.js' {333 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-jest-import'>;334}335declare module 'eslint-plugin-jest/rules/no-large-snapshots.js' {336 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-large-snapshots'>;337}338declare module 'eslint-plugin-jest/rules/no-test-callback.js' {339 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-test-callback'>;340}341declare module 'eslint-plugin-jest/rules/no-test-prefixes.js' {342 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-test-prefixes'>;343}344declare module 'eslint-plugin-jest/rules/no-test-return-statement.js' {345 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-test-return-statement'>;346}347declare module 'eslint-plugin-jest/rules/no-truthy-falsy.js' {348 declare module.exports: $Exports<'eslint-plugin-jest/rules/no-truthy-falsy'>;349}350declare module 'eslint-plugin-jest/rules/prefer-called-with.js' {351 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-called-with'>;352}353declare module 'eslint-plugin-jest/rules/prefer-expect-assertions.js' {354 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-expect-assertions'>;355}356declare module 'eslint-plugin-jest/rules/prefer-inline-snapshots.js' {357 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-inline-snapshots'>;358}359declare module 'eslint-plugin-jest/rules/prefer-spy-on.js' {360 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-spy-on'>;361}362declare module 'eslint-plugin-jest/rules/prefer-strict-equal.js' {363 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-strict-equal'>;364}365declare module 'eslint-plugin-jest/rules/prefer-to-be-null.js' {366 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-to-be-null'>;367}368declare module 'eslint-plugin-jest/rules/prefer-to-be-undefined.js' {369 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-to-be-undefined'>;370}371declare module 'eslint-plugin-jest/rules/prefer-to-contain.js' {372 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-to-contain'>;373}374declare module 'eslint-plugin-jest/rules/prefer-to-have-length.js' {375 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-to-have-length'>;376}377declare module 'eslint-plugin-jest/rules/prefer-todo.js' {378 declare module.exports: $Exports<'eslint-plugin-jest/rules/prefer-todo'>;379}380declare module 'eslint-plugin-jest/rules/require-tothrow-message.js' {381 declare module.exports: $Exports<'eslint-plugin-jest/rules/require-tothrow-message'>;382}383declare module 'eslint-plugin-jest/rules/util.js' {384 declare module.exports: $Exports<'eslint-plugin-jest/rules/util'>;385}386declare module 'eslint-plugin-jest/rules/valid-describe.js' {387 declare module.exports: $Exports<'eslint-plugin-jest/rules/valid-describe'>;388}389declare module 'eslint-plugin-jest/rules/valid-expect-in-promise.js' {390 declare module.exports: $Exports<'eslint-plugin-jest/rules/valid-expect-in-promise'>;391}392declare module 'eslint-plugin-jest/rules/valid-expect.js' {393 declare module.exports: $Exports<'eslint-plugin-jest/rules/valid-expect'>;...
setup.js
Source:setup.js
1/**2 * Copyright (c) Facebook, Inc. and its affiliates.3 *4 * This source code is licensed under the MIT license found in the5 * LICENSE file in the root directory of this source tree.6 *7 * @format8 */9'use strict';10const MockNativeMethods = jest.requireActual('./MockNativeMethods');11const mockComponent = jest.requireActual('./mockComponent');12jest.requireActual('../Libraries/polyfills/Object.es7.js');13jest.requireActual('../Libraries/polyfills/error-guard');14global.__DEV__ = true;15global.Promise = jest.requireActual('promise');16global.regeneratorRuntime = jest.requireActual('regenerator-runtime/runtime');17global.requestAnimationFrame = function(callback) {18 return setTimeout(callback, 0);19};20global.cancelAnimationFrame = function(id) {21 clearTimeout(id);22};23// there's a __mock__ for it.24jest.setMock(25 '../Libraries/vendor/core/ErrorUtils',26 require('../Libraries/vendor/core/ErrorUtils'),27);28jest29 .mock('../Libraries/Core/InitializeCore', () => {})30 .mock('../Libraries/ReactNative/UIManager', () => ({31 AndroidViewPager: {32 Commands: {33 setPage: jest.fn(),34 setPageWithoutAnimation: jest.fn(),35 },36 },37 blur: jest.fn(),38 createView: jest.fn(),39 customBubblingEventTypes: {},40 customDirectEventTypes: {},41 dispatchViewManagerCommand: jest.fn(),42 focus: jest.fn(),43 getViewManagerConfig: jest.fn(name => {44 if (name === 'AndroidDrawerLayout') {45 return {46 Constants: {47 DrawerPosition: {48 Left: 10,49 },50 },51 };52 }53 }),54 measure: jest.fn(),55 manageChildren: jest.fn(),56 removeSubviewsFromContainerWithID: jest.fn(),57 replaceExistingNonRootView: jest.fn(),58 setChildren: jest.fn(),59 updateView: jest.fn(),60 AndroidDrawerLayout: {61 Constants: {62 DrawerPosition: {63 Left: 10,64 },65 },66 },67 AndroidTextInput: {68 Commands: {},69 },70 ScrollView: {71 Constants: {},72 },73 View: {74 Constants: {},75 },76 }))77 .mock('../Libraries/Image/Image', () =>78 mockComponent('../Libraries/Image/Image'),79 )80 .mock('../Libraries/Text/Text', () =>81 mockComponent('../Libraries/Text/Text', MockNativeMethods),82 )83 .mock('../Libraries/Components/TextInput/TextInput', () =>84 mockComponent('../Libraries/Components/TextInput/TextInput'),85 )86 .mock('../Libraries/Modal/Modal', () =>87 mockComponent('../Libraries/Modal/Modal'),88 )89 .mock('../Libraries/Components/View/View', () =>90 mockComponent('../Libraries/Components/View/View', MockNativeMethods),91 )92 .mock('../Libraries/Components/AccessibilityInfo/AccessibilityInfo', () => ({93 addEventListener: jest.fn(),94 announceForAccessibility: jest.fn(),95 fetch: jest.fn(),96 isBoldTextEnabled: jest.fn(),97 isGrayscaleEnabled: jest.fn(),98 isInvertColorsEnabled: jest.fn(),99 isReduceMotionEnabled: jest.fn(),100 isReduceTransparencyEnabled: jest.fn(),101 isScreenReaderEnabled: jest.fn(),102 removeEventListener: jest.fn(),103 setAccessibilityFocus: jest.fn(),104 }))105 .mock('../Libraries/Components/RefreshControl/RefreshControl', () =>106 jest.requireActual(107 '../Libraries/Components/RefreshControl/__mocks__/RefreshControlMock',108 ),109 )110 .mock('../Libraries/Components/ScrollView/ScrollView', () =>111 jest.requireActual(112 '../Libraries/Components/ScrollView/__mocks__/ScrollViewMock',113 ),114 )115 .mock('../Libraries/Components/ActivityIndicator/ActivityIndicator', () =>116 mockComponent(117 '../Libraries/Components/ActivityIndicator/ActivityIndicator',118 ),119 )120 .mock('../Libraries/Animated/src/Animated', () => {121 const Animated = jest.requireActual('../Libraries/Animated/src/Animated');122 Animated.Text.__skipSetNativeProps_FOR_TESTS_ONLY = true;123 Animated.View.__skipSetNativeProps_FOR_TESTS_ONLY = true;124 return Animated;125 })126 .mock('../Libraries/Animated/src/AnimatedImplementation', () => {127 const AnimatedImplementation = jest.requireActual(128 '../Libraries/Animated/src/AnimatedImplementation',129 );130 const oldCreate = AnimatedImplementation.createAnimatedComponent;131 AnimatedImplementation.createAnimatedComponent = function(132 Component,133 defaultProps,134 ) {135 const Wrapped = oldCreate(Component, defaultProps);136 Wrapped.__skipSetNativeProps_FOR_TESTS_ONLY = true;137 return Wrapped;138 };139 return AnimatedImplementation;140 })141 .mock('../Libraries/AppState/AppState', () => ({142 addEventListener: jest.fn(),143 removeEventListener: jest.fn(),144 }))145 .mock('../Libraries/Linking/Linking', () => ({146 openURL: jest.fn(),147 canOpenURL: jest.fn(() => Promise.resolve(true)),148 openSettings: jest.fn(),149 addEventListener: jest.fn(),150 getInitialURL: jest.fn(() => Promise.resolve()),151 removeEventListener: jest.fn(),152 sendIntent: jest.fn(),153 }))154 .mock('../Libraries/Renderer/shims/ReactNative', () => {155 const ReactNative = jest.requireActual(156 '../Libraries/Renderer/shims/ReactNative',157 );158 const NativeMethodsMixin =159 ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED160 .NativeMethodsMixin;161 Object.assign(NativeMethodsMixin, MockNativeMethods);162 Object.assign(ReactNative.NativeComponent.prototype, MockNativeMethods);163 return ReactNative;164 })165 // Mock modules defined by the native layer (ex: Objective-C, Java)166 .mock('../Libraries/BatchedBridge/NativeModules', () => ({167 AlertManager: {168 alertWithArgs: jest.fn(),169 },170 AsyncLocalStorage: {171 multiGet: jest.fn((keys, callback) =>172 process.nextTick(() => callback(null, [])),173 ),174 multiSet: jest.fn((entries, callback) =>175 process.nextTick(() => callback(null)),176 ),177 multiRemove: jest.fn((keys, callback) =>178 process.nextTick(() => callback(null)),179 ),180 multiMerge: jest.fn((entries, callback) =>181 process.nextTick(() => callback(null)),182 ),183 clear: jest.fn(callback => process.nextTick(() => callback(null))),184 getAllKeys: jest.fn(callback =>185 process.nextTick(() => callback(null, [])),186 ),187 },188 Clipboard: {189 getString: jest.fn(() => ''),190 setString: jest.fn(),191 },192 DeviceInfo: {193 getConstants() {194 return {195 Dimensions: {196 window: {197 fontScale: 2,198 height: 1334,199 scale: 2,200 width: 750,201 },202 screen: {203 fontScale: 2,204 height: 1334,205 scale: 2,206 width: 750,207 },208 },209 };210 },211 },212 ImageLoader: {213 getSize: jest.fn(url => Promise.resolve({width: 320, height: 240})),214 prefetchImage: jest.fn(),215 },216 ImageViewManager: {217 getSize: jest.fn((uri, success) =>218 process.nextTick(() => success(320, 240)),219 ),220 prefetchImage: jest.fn(),221 },222 KeyboardObserver: {223 addListener: jest.fn(),224 removeListeners: jest.fn(),225 },226 Networking: {227 sendRequest: jest.fn(),228 abortRequest: jest.fn(),229 addListener: jest.fn(),230 removeListeners: jest.fn(),231 },232 PlatformConstants: {233 getConstants() {234 return {};235 },236 },237 PushNotificationManager: {238 presentLocalNotification: jest.fn(),239 scheduleLocalNotification: jest.fn(),240 cancelAllLocalNotifications: jest.fn(),241 removeAllDeliveredNotifications: jest.fn(),242 getDeliveredNotifications: jest.fn(callback =>243 process.nextTick(() => []),244 ),245 removeDeliveredNotifications: jest.fn(),246 setApplicationIconBadgeNumber: jest.fn(),247 getApplicationIconBadgeNumber: jest.fn(callback =>248 process.nextTick(() => callback(0)),249 ),250 cancelLocalNotifications: jest.fn(),251 getScheduledLocalNotifications: jest.fn(callback =>252 process.nextTick(() => callback()),253 ),254 requestPermissions: jest.fn(() =>255 Promise.resolve({alert: true, badge: true, sound: true}),256 ),257 abandonPermissions: jest.fn(),258 checkPermissions: jest.fn(callback =>259 process.nextTick(() =>260 callback({alert: true, badge: true, sound: true}),261 ),262 ),263 getInitialNotification: jest.fn(() => Promise.resolve(null)),264 addListener: jest.fn(),265 removeListeners: jest.fn(),266 },267 SourceCode: {268 getConstants() {269 return {270 scriptURL: null,271 };272 },273 },274 StatusBarManager: {275 setColor: jest.fn(),276 setStyle: jest.fn(),277 setHidden: jest.fn(),278 setNetworkActivityIndicatorVisible: jest.fn(),279 setBackgroundColor: jest.fn(),280 setTranslucent: jest.fn(),281 getConstants: () => ({282 HEIGHT: 42,283 }),284 },285 Timing: {286 createTimer: jest.fn(),287 deleteTimer: jest.fn(),288 },289 UIManager: {},290 BlobModule: {291 getConstants: () => ({BLOB_URI_SCHEME: 'content', BLOB_URI_HOST: null}),292 addNetworkingHandler: jest.fn(),293 enableBlobSupport: jest.fn(),294 disableBlobSupport: jest.fn(),295 createFromParts: jest.fn(),296 sendBlob: jest.fn(),297 release: jest.fn(),298 },299 WebSocketModule: {300 connect: jest.fn(),301 send: jest.fn(),302 sendBinary: jest.fn(),303 ping: jest.fn(),304 close: jest.fn(),305 addListener: jest.fn(),306 removeListeners: jest.fn(),307 },308 I18nManager: {309 allowRTL: jest.fn(),310 forceRTL: jest.fn(),311 swapLeftAndRightInRTL: jest.fn(),312 getConstants: () => ({313 isRTL: false,314 doLeftAndRightSwapInRTL: true,315 }),316 },317 }))318 .mock('../Libraries/ReactNative/requireNativeComponent', () => {319 const React = require('react');320 return viewName => {321 const Component = class extends React.Component {322 render() {323 return React.createElement(viewName, this.props, this.props.children);324 }325 };326 if (viewName === 'RCTView') {327 Component.displayName = 'View';328 } else {329 Component.displayName = viewName;330 }331 return Component;332 };333 })334 .mock(335 '../Libraries/Utilities/verifyComponentAttributeEquivalence',336 () => function() {},337 )338 .mock('../Libraries/Components/View/ViewNativeComponent', () => {339 const React = require('react');340 const Component = class extends React.Component {341 render() {342 return React.createElement('View', this.props, this.props.children);343 }344 };345 Component.displayName = 'View';346 return {347 __esModule: true,348 default: Component,349 };...
Using AI Code Generation
1import initStoryshots from '@storybook/addon-storyshots';2initStoryshots();3import initStoryshots from '@storybook/addon-storyshots';4initStoryshots({5});6import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots';7initStoryshots({8 test: multiSnapshotWithOptions({}),9});10import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots';11initStoryshots({12 test: multiSnapshotWithOptions({13 renderer: createSerializer({ mode: 'deep' }),14 }),15});16import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots';17initStoryshots({18 test: multiSnapshotWithOptions({19 renderer: createSerializer({ mode: 'deep' }),20 createNodeMock: element => document.createElement('div'),21 }),22});23import initStoryshots, { multiSnapshotWithOptions } from '@storybook/addon-storyshots';24initStoryshots({25 test: multiSnapshotWithOptions({26 renderer: createSerializer({ mode: 'deep' }),27 createNodeMock: element => document.createElement('div'),28 }),29});30import initStoryshots from '@storybook/addon-storyshots';31import { imageSnapshot } from '@storybook/addon-storyshots-puppeteer';32initStoryshots({33 test: imageSnapshot(),34});35import initStoryshots from '@storybook/addon-storyshots';36import { imageSnapshot } from '@storybook/addon-storyshots-puppeteer';37initStoryshots({38 test: imageSnapshot({39 }),40});41import initStoryshots
Using AI Code Generation
1import initStoryshots from '@storybook/addon-storyshots';2initStoryshots();3"scripts": {4 },5 "devDependencies": {6 }7 ✓ renders a button (5ms)
Using AI Code Generation
1import initStoryshots from '@storybook/addon-storyshots';2initStoryshots();3import initStoryshots from '@storybook/addon-storyshots';4initStoryshots();5"scripts": {6}7module.exports = {8 transform: {9 '.*\\.(vue)$': '<rootDir>/node_modules/jest-vue-preprocessor'10 },11 moduleNameMapper: {12 '^@/(.*)$': '<rootDir>/src/$1'13 },14 '<rootDir>/test/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'15}16"scripts": {17}18module.exports = {19 transform: {20 '.*\\.(vue)$': '<rootDir>/node_modules/jest-vue-preprocessor'21 },22 moduleNameMapper: {23 '^@/(.*)$': '<rootDir>/src/$1'24 },25 '<rootDir>/test/unit/**/*.spec.(js|jsx|ts|tsx)|**/__tests__/*.(js|jsx|ts|tsx)'26}27"scripts": {28}29module.exports = {30 transform: {
Using AI Code Generation
1const testRunner = require('jest-runner');2const { createStorybookTestRunner } = require('storybook-test-runner');3const storybookTestRunner = createStorybookTestRunner(testRunner);4module.exports = storybookTestRunner;5"scripts": {6 },7"jest": {8 }
Using AI Code Generation
1const { configure } = require('jest-circus');2const { withTests } = require('@storybook/addon-jest');3const results = require('../.jest-test-results.json');4configure(() => {5 require('../stories/Welcome.stories.js');6 require('../stories/Welcome.stories.tsx');7 require('../stories/Welcome.stories.jsx');8 require('../stories/Welcome.stories.mdx');9 require('../stories/Button.stories.js');10 require('../stories/Button.stories.tsx');11 require('../stories/Button.stories.jsx');12 require('../stories/Button.stories.mdx');13}, module);14const jestTestResults = withTests({ results });15module.exports = {16};17{18 "dependencies": {19 },20 "devDependencies": {
Using AI Code Generation
1import initStoryshots from "@storybook/addon-storyshots";2initStoryshots();3"scripts": {4 }5import initStoryshots from "@storybook/addon-storyshots";6import { imageSnapshot } from "@storybook/addon-storyshots-puppeteer";7initStoryshots({ suite: "Image storyshots", test: imageSnapshot() });8import initStoryshots from "@storybook/addon-storyshots";9import { multiSnapshotWithOptions } from "@storybook/addon-storyshots";10initStoryshots({11 test: multiSnapshotWithOptions(),12});13import initStoryshots from "@storybook/addon-storyshots";14import { multiSnapshotWithOptions } from "@storybook/addon-storyshots";15initStoryshots({16 test: multiSnapshotWithOptions({17 renderer: createSerializer(),18 }),19});20import initStoryshots from "@storybook/addon-storyshots";21import { multiSnapshotWithOptions } from "@storybook/addon-storyshots";22initStoryshots({23 test: multiSnapshotWithOptions({24 renderer: createSerializer({ mode: "deep" }),25 }),26});27import initStoryshots from "@storybook/addon-storyshots";28import { multiSnapshotWithOptions } from "@storybook/addon-storyshots";29initStoryshots({30 test: multiSnapshotWithOptions({31 renderer: createSerializer({ mode: "deep" }),32 }),33});34import initStoryshots from "@storybook/addon-storyshots";35import { multiSnapshotWithOptions } from "@storybook/addon-storyshots";36initStoryshots({
Using AI Code Generation
1import { jest } from "@storybook/testing-react";2const storybook = jest("./src");3storybook.addTest("Button", "default", () => {4 const { getByText } = storybook.render("Button", "default");5 expect(getByText("Hello Button")).toBeInTheDocument();6});7storybook.run();8module.exports = {9};10import { addDecorator } from "@storybook/react";11import { withA11y } from "@storybook/addon-a11y";12import { withKnobs } from "@storybook/addon-knobs";13import { withInfo } from "@storybook/addon-info";14import { withViewport } from "@storybook/addon-viewport";15import React from "react";16import { ThemeProvider } from "styled-components";17import { GlobalStyles } from "../src/theme/globalStyles";18import { theme } from "../src/theme/theme";19addDecorator(withA11y);20addDecorator(withKnobs);21addDecorator(withInfo);22addDecorator(withViewport);23addDecorator((story) => (24 <ThemeProvider theme={theme}>25 {story()}26));27const path = require("path");28const { CleanWebpackPlugin } = require("clean-webpack-plugin");29module.exports = ({ config }) => {30 config.resolve.alias = {31 "@components": path.resolve(__dirname, "../src/components"),32 "@containers": path.resolve(__dirname, "../src/containers"),33 "@pages": path.resolve(__dirname, "../src/pages"),34 "@theme": path.resolve(__dirname, "../src/theme"),35 "@utils": path.resolve(__dirname, "../src/utils"),36 };37 config.plugins.push(new CleanWebpackPlugin());38 return config;39};40{41 "compilerOptions": {
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!