How to use toMatchSnapshot method in differencify

Best JavaScript code snippet using differencify

createConfig.test.js

Source:createConfig.test.js Github

copy

Full Screen

...14 it('simple', () => {15 const config = createConfig(webpackConfig, Object.assign({}, argv), {16 port: 8080,17 });18 expect(config).toMatchSnapshot();19 });20 it('bonjour option', () => {21 const config = createConfig(22 webpackConfig,23 Object.assign({}, argv, {24 bonjour: true,25 }),26 { port: 8080 }27 );28 expect(config).toMatchSnapshot();29 });30 it('bonjour option (devServer config)', () => {31 const config = createConfig(32 Object.assign({}, webpackConfig, { devServer: { bonjour: true } }),33 argv,34 { port: 8080 }35 );36 expect(config).toMatchSnapshot();37 });38 it('host option', () => {39 const config = createConfig(40 webpackConfig,41 Object.assign({}, argv, {42 host: 'example.dev',43 }),44 { port: 8080 }45 );46 expect(config).toMatchSnapshot();47 });48 it('host option (localhost)', () => {49 const config = createConfig(50 webpackConfig,51 Object.assign({}, argv, {52 host: 'localhost',53 }),54 { port: 8080 }55 );56 expect(config).toMatchSnapshot();57 });58 it('host option (undefined)', () => {59 const config = createConfig(60 webpackConfig,61 Object.assign({}, argv, {62 // eslint-disable-next-line no-undefined63 host: undefined,64 }),65 { port: 8080 }66 );67 expect(config).toMatchSnapshot();68 });69 it('host option (null)', () => {70 const config = createConfig(71 webpackConfig,72 Object.assign({}, argv, {73 // eslint-disable-next-line no-undefined74 host: null,75 }),76 { port: 8080 }77 );78 expect(config).toMatchSnapshot();79 });80 it('host option (devServer config)', () => {81 const config = createConfig(82 Object.assign({}, webpackConfig, { devServer: { host: 'example.dev' } }),83 argv,84 { port: 8080 }85 );86 expect(config).toMatchSnapshot();87 });88 it('host option (specify for CLI and devServer config)', () => {89 const config = createConfig(90 Object.assign({}, webpackConfig, { devServer: { host: 'example.dev' } }),91 Object.assign({}, argv, { host: 'other.dev' }),92 { port: 8080 }93 );94 expect(config).toMatchSnapshot();95 });96 it('allowedHosts option', () => {97 const config = createConfig(98 webpackConfig,99 Object.assign({}, argv, {100 allowedHosts: '.host.com,host2.com',101 }),102 { port: 8080 }103 );104 expect(config).toMatchSnapshot();105 });106 it('allowedHosts option (devServer config)', () => {107 const config = createConfig(108 Object.assign({}, webpackConfig, {109 devServer: { allowedHosts: ['.host.com', 'host2.com'] },110 }),111 argv,112 { port: 8080 }113 );114 expect(config).toMatchSnapshot();115 });116 it('public option', () => {117 const config = createConfig(118 webpackConfig,119 Object.assign({}, argv, {120 public: true,121 }),122 { port: 8080 }123 );124 expect(config).toMatchSnapshot();125 });126 it('public option (devServer config)', () => {127 const config = createConfig(128 Object.assign({}, webpackConfig, {129 devServer: { public: true },130 }),131 argv,132 { port: 8080 }133 );134 expect(config).toMatchSnapshot();135 });136 it('socket option', () => {137 const config = createConfig(138 webpackConfig,139 Object.assign({}, argv, {140 socket: 'socket',141 }),142 { port: 8080 }143 );144 expect(config).toMatchSnapshot();145 });146 it('socket option (devServer config)', () => {147 const config = createConfig(148 Object.assign({}, webpackConfig, {149 devServer: { socket: 'socket' },150 }),151 argv,152 { port: 8080 }153 );154 expect(config).toMatchSnapshot();155 });156 it('progress option', () => {157 const config = createConfig(158 webpackConfig,159 Object.assign({}, argv, {160 progress: true,161 }),162 { port: 8080 }163 );164 expect(config).toMatchSnapshot();165 });166 it('progress option (devServer config)', () => {167 const config = createConfig(168 Object.assign({}, webpackConfig, {169 devServer: { progress: true },170 }),171 argv,172 { port: 8080 }173 );174 expect(config).toMatchSnapshot();175 });176 it('publicPath option (not specify)', () => {177 const config = createConfig(webpackConfig, argv, { port: 8080 });178 expect(config).toMatchSnapshot();179 });180 it('publicPath option (path in devServer option)', () => {181 const config = createConfig(182 Object.assign({}, webpackConfig, {183 devServer: { publicPath: '/assets/' },184 }),185 argv,186 { port: 8080 }187 );188 expect(config).toMatchSnapshot();189 });190 it('publicPath option (url in devServer option)', () => {191 const config = createConfig(192 Object.assign({}, webpackConfig, {193 devServer: { publicPath: 'http://localhost:8080/assets/' },194 }),195 argv,196 { port: 8080 }197 );198 expect(config).toMatchSnapshot();199 });200 it('publicPath option (url in output option)', () => {201 const config = createConfig(202 Object.assign({}, webpackConfig, {203 output: { publicPath: 'http://localhost:8080/assets/' },204 }),205 argv,206 { port: 8080 }207 );208 expect(config).toMatchSnapshot();209 });210 it('publicPath option (path in output option)', () => {211 const config = createConfig(212 Object.assign({}, webpackConfig, {213 output: { publicPath: '/assets/' },214 }),215 argv,216 { port: 8080 }217 );218 expect(config).toMatchSnapshot();219 });220 it('publicPath option (path without starting slash in output option)', () => {221 const config = createConfig(222 Object.assign({}, webpackConfig, {223 output: { publicPath: 'assets/' },224 }),225 argv,226 { port: 8080 }227 );228 expect(config).toMatchSnapshot();229 });230 it('filename option (in webpack config)', () => {231 const config = createConfig(232 Object.assign({}, webpackConfig, {233 output: { filename: '[name]-bundle.js' },234 }),235 argv,236 { port: 8080 }237 );238 expect(config).toMatchSnapshot();239 });240 it('filename option (in output config)', () => {241 const config = createConfig(242 Object.assign({}, webpackConfig, {243 output: { filename: '[name]-output-bundle.js' },244 }),245 argv,246 { port: 8080 }247 );248 expect(config).toMatchSnapshot();249 });250 it('filename option (in devServer config)', () => {251 const config = createConfig(252 Object.assign({}, webpackConfig, {253 devServer: { filename: '[name]-dev-server-bundle.js' },254 }),255 argv,256 { port: 8080 }257 );258 expect(config).toMatchSnapshot();259 });260 it('watchOptions option (in output config)', () => {261 const config = createConfig(262 Object.assign({}, webpackConfig, {263 watchOptions: { poll: true },264 }),265 argv,266 { port: 8080 }267 );268 expect(config).toMatchSnapshot();269 });270 it('watchOptions option (in devServer config)', () => {271 const config = createConfig(272 Object.assign({}, webpackConfig, {273 devServer: { watchOptions: { poll: true } },274 }),275 argv,276 { port: 8080 }277 );278 expect(config).toMatchSnapshot();279 });280 it('hot option', () => {281 const config = createConfig(282 webpackConfig,283 Object.assign({}, argv, { hot: true }),284 { port: 8080 }285 );286 expect(config).toMatchSnapshot();287 });288 it('hot option (in devServer config)', () => {289 const config = createConfig(290 Object.assign({}, webpackConfig, {291 devServer: { hot: true },292 }),293 argv,294 { port: 8080 }295 );296 expect(config).toMatchSnapshot();297 });298 it('hotOnly option', () => {299 const config = createConfig(300 webpackConfig,301 Object.assign({}, argv, { hotOnly: true }),302 { port: 8080 }303 );304 expect(config).toMatchSnapshot();305 });306 it('hotOnly option (in devServer config)', () => {307 const config = createConfig(308 Object.assign({}, webpackConfig, {309 devServer: { hotOnly: true },310 }),311 argv,312 { port: 8080 }313 );314 expect(config).toMatchSnapshot();315 });316 it('clientLogLevel option', () => {317 const config = createConfig(318 webpackConfig,319 Object.assign({}, argv, { clientLogLevel: 'none' }),320 { port: 8080 }321 );322 expect(config).toMatchSnapshot();323 });324 it('clientLogLevel option (in devServer config)', () => {325 const config = createConfig(326 Object.assign({}, webpackConfig, {327 devServer: { clientLogLevel: 'none' },328 }),329 argv,330 { port: 8080 }331 );332 expect(config).toMatchSnapshot();333 });334 it('contentBase option (string)', () => {335 const config = createConfig(336 webpackConfig,337 Object.assign({}, argv, { contentBase: 'assets' }),338 { port: 8080 }339 );340 config.contentBase = path.relative(process.cwd(), config.contentBase);341 expect(config).toMatchSnapshot();342 });343 it('contentBase option (array)', () => {344 const config = createConfig(345 webpackConfig,346 Object.assign({}, argv, { contentBase: ['assets', 'static'] }),347 { port: 8080 }348 );349 config.contentBase = config.contentBase.map((item) =>350 path.relative(process.cwd(), item)351 );352 expect(config).toMatchSnapshot();353 });354 it('contentBase option (boolean)', () => {355 const config = createConfig(356 webpackConfig,357 Object.assign({}, argv, { contentBase: false }),358 { port: 8080 }359 );360 expect(config).toMatchSnapshot();361 });362 it('contentBase option (string) (in devServer config)', () => {363 const config = createConfig(364 Object.assign({}, webpackConfig, {365 devServer: { contentBase: 'assets' },366 }),367 argv,368 { port: 8080 }369 );370 config.contentBase = path.relative(process.cwd(), config.contentBase);371 expect(config).toMatchSnapshot();372 });373 it('watchContentBase option', () => {374 const config = createConfig(375 webpackConfig,376 Object.assign({}, argv, { watchContentBase: true }),377 { port: 8080 }378 );379 expect(config).toMatchSnapshot();380 });381 it('watchContentBase option (in devServer config)', () => {382 const config = createConfig(383 Object.assign({}, webpackConfig, {384 devServer: { watchContentBase: true },385 }),386 argv,387 { port: 8080 }388 );389 expect(config).toMatchSnapshot();390 });391 it('stats option', () => {392 const config = createConfig(393 Object.assign({}, webpackConfig, {394 devServer: { stats: 'errors-only' },395 }),396 argv,397 { port: 8080 }398 );399 expect(config).toMatchSnapshot();400 });401 it('stats option (colors)', () => {402 const config = createConfig(403 Object.assign({}, webpackConfig, {404 devServer: { stats: { errors: true } },405 }),406 Object.assign({}, argv, { color: true }),407 { port: 8080 }408 );409 expect(config).toMatchSnapshot();410 });411 it('lazy option', () => {412 const config = createConfig(413 webpackConfig,414 Object.assign({}, argv, { lazy: true }),415 { port: 8080 }416 );417 expect(config).toMatchSnapshot();418 });419 it('lazy option (in devServer config)', () => {420 const config = createConfig(421 Object.assign({}, webpackConfig, {422 devServer: { lazy: true },423 }),424 argv,425 { port: 8080 }426 );427 expect(config).toMatchSnapshot();428 });429 it('info option', () => {430 const config = createConfig(431 webpackConfig,432 Object.assign({}, argv, { info: false }),433 { port: 8080 }434 );435 expect(config).toMatchSnapshot();436 });437 it('info option (in devServer config)', () => {438 const config = createConfig(439 Object.assign({}, webpackConfig, {440 devServer: { noInfo: false },441 }),442 argv,443 { port: 8080 }444 );445 expect(config).toMatchSnapshot();446 });447 it('mimeTypes option', () => {448 const config = createConfig(449 Object.assign({}, webpackConfig, {450 devServer: { mimeTypes: { 'text/html': ['phtml'] } },451 }),452 argv,453 { port: 8080 }454 );455 expect(config).toMatchSnapshot();456 });457 it('mimeTypes option - with force', () => {458 const config = createConfig(459 Object.assign({}, webpackConfig, {460 devServer: {461 mimeTypes: { typeMap: { 'text/html': ['phtml'] }, force: true },462 },463 }),464 argv,465 { port: 8080 }466 );467 expect(config).toMatchSnapshot();468 });469 it('quiet option', () => {470 const config = createConfig(471 webpackConfig,472 Object.assign({}, argv, { quiet: true }),473 { port: 8080 }474 );475 expect(config).toMatchSnapshot();476 });477 it('quiet option (in devServer config)', () => {478 const config = createConfig(479 Object.assign({}, webpackConfig, {480 devServer: { quiet: true },481 }),482 argv,483 { port: 8080 }484 );485 expect(config).toMatchSnapshot();486 });487 it('https option', () => {488 const config = createConfig(489 webpackConfig,490 Object.assign({}, argv, { https: true }),491 { port: 8080 }492 );493 expect(config).toMatchSnapshot();494 });495 it('https option (in devServer config)', () => {496 const config = createConfig(497 Object.assign({}, webpackConfig, {498 devServer: { https: true },499 }),500 argv,501 { port: 8080 }502 );503 expect(config).toMatchSnapshot();504 });505 it('http2 option', () => {506 const config = createConfig(507 webpackConfig,508 Object.assign({}, argv, { https: true, http2: true }),509 { port: 8080 }510 );511 expect(config).toMatchSnapshot();512 });513 it('http2 option (in devServer config)', () => {514 const config = createConfig(515 Object.assign({}, webpackConfig, {516 devServer: { https: true, http2: true },517 }),518 argv,519 { port: 8080 }520 );521 expect(config).toMatchSnapshot();522 });523 it('key option', () => {524 const config = createConfig(525 webpackConfig,526 Object.assign({}, argv, { https: true, key: '/path/to/server.key' }),527 { port: 8080 }528 );529 expect(config).toMatchSnapshot();530 });531 it('key option (in devServer config)', () => {532 const config = createConfig(533 Object.assign({}, webpackConfig, {534 devServer: { https: true, key: '/path/to/server.key' },535 }),536 argv,537 { port: 8080 }538 );539 expect(config).toMatchSnapshot();540 });541 it('cert option', () => {542 const config = createConfig(543 webpackConfig,544 Object.assign({}, argv, { https: true, cert: '/path/to/server.crt' }),545 { port: 8080 }546 );547 expect(config).toMatchSnapshot();548 });549 it('cert option (in devServer config)', () => {550 const config = createConfig(551 Object.assign({}, webpackConfig, {552 devServer: { https: true, cert: '/path/to/server.crt' },553 }),554 argv,555 { port: 8080 }556 );557 expect(config).toMatchSnapshot();558 });559 it('cacert option', () => {560 const config = createConfig(561 webpackConfig,562 Object.assign({}, argv, { https: true, cacert: '/path/to/ca.pem' }),563 { port: 8080 }564 );565 expect(config).toMatchSnapshot();566 });567 it('cacert option (in devServer config)', () => {568 const config = createConfig(569 Object.assign({}, webpackConfig, {570 // TODO rename `ca` to `cacert` for `v4` to avoid difference between CLI and configuration571 devServer: { https: true, ca: '/path/to/ca.pem' },572 }),573 argv,574 { port: 8080 }575 );576 expect(config).toMatchSnapshot();577 });578 it('pfx option', () => {579 const config = createConfig(580 webpackConfig,581 Object.assign({}, argv, { https: true, pfx: '/path/to/file.pfx' }),582 { port: 8080 }583 );584 expect(config).toMatchSnapshot();585 });586 it('pfx option (in devServer config)', () => {587 const config = createConfig(588 Object.assign({}, webpackConfig, {589 devServer: { https: true, pfx: '/path/to/file.pfx' },590 }),591 argv,592 { port: 8080 }593 );594 expect(config).toMatchSnapshot();595 });596 it('pfxPassphrase option', () => {597 const config = createConfig(598 webpackConfig,599 Object.assign({}, argv, { pfxPassphrase: 'passphrase' }),600 { port: 8080 }601 );602 expect(config).toMatchSnapshot();603 });604 it('https option (in devServer config)', () => {605 const config = createConfig(606 Object.assign({}, webpackConfig, {607 devServer: { pfxPassphrase: 'passphrase' },608 }),609 argv,610 { port: 8080 }611 );612 expect(config).toMatchSnapshot();613 });614 it('inline option', () => {615 const config = createConfig(616 webpackConfig,617 Object.assign({}, argv, { inline: false }),618 { port: 8080 }619 );620 expect(config).toMatchSnapshot();621 });622 it('inline option (in devServer config)', () => {623 const config = createConfig(624 Object.assign({}, webpackConfig, {625 devServer: { inline: false },626 }),627 argv,628 { port: 8080 }629 );630 expect(config).toMatchSnapshot();631 });632 it('historyApiFallback option', () => {633 const config = createConfig(634 webpackConfig,635 Object.assign({}, argv, { historyApiFallback: true }),636 { port: 8080 }637 );638 expect(config).toMatchSnapshot();639 });640 it('historyApiFallback option (in devServer config)', () => {641 const config = createConfig(642 Object.assign({}, webpackConfig, {643 devServer: { historyApiFallback: true },644 }),645 argv,646 { port: 8080 }647 );648 expect(config).toMatchSnapshot();649 });650 it('compress option', () => {651 const config = createConfig(652 webpackConfig,653 Object.assign({}, argv, { compress: true }),654 { port: 8080 }655 );656 expect(config).toMatchSnapshot();657 });658 it('compress option (in devServer config)', () => {659 const config = createConfig(660 Object.assign({}, webpackConfig, {661 devServer: { compress: true },662 }),663 argv,664 { port: 8080 }665 );666 expect(config).toMatchSnapshot();667 });668 it('disableHostCheck option', () => {669 const config = createConfig(670 webpackConfig,671 Object.assign({}, argv, { disableHostCheck: true }),672 { port: 8080 }673 );674 expect(config).toMatchSnapshot();675 });676 it('disableHostCheck option (in devServer config)', () => {677 const config = createConfig(678 Object.assign({}, webpackConfig, {679 devServer: { disableHostCheck: true },680 }),681 argv,682 { port: 8080 }683 );684 expect(config).toMatchSnapshot();685 });686 it('open option (boolean)', () => {687 const config = createConfig(688 webpackConfig,689 Object.assign({}, argv, { open: true }),690 { port: 8080 }691 );692 expect(config).toMatchSnapshot();693 });694 it('open option (boolean) (in devServer config)', () => {695 const config = createConfig(696 Object.assign({}, webpackConfig, {697 devServer: { open: true },698 }),699 argv,700 { port: 8080 }701 );702 expect(config).toMatchSnapshot();703 });704 it('open option (string)', () => {705 const config = createConfig(706 webpackConfig,707 Object.assign({}, argv, { open: 'Google Chrome' }),708 { port: 8080 }709 );710 expect(config).toMatchSnapshot();711 });712 it('open option (object)', () => {713 const config = createConfig(714 webpackConfig,715 {716 ...argv,717 open: {718 app: ['Google Chrome', '--incognito'],719 },720 },721 { port: 8080 }722 );723 expect(config).toMatchSnapshot();724 });725 it('openPage option', () => {726 const config = createConfig(727 webpackConfig,728 Object.assign({}, argv, { openPage: '/different/page' }),729 { port: 8080 }730 );731 expect(config).toMatchSnapshot();732 });733 it('openPage option (in devServer config)', () => {734 const config = createConfig(735 Object.assign({}, webpackConfig, {736 devServer: { open: true, openPage: '/different/page' },737 }),738 argv,739 { port: 8080 }740 );741 expect(config).toMatchSnapshot();742 });743 it('openPage multiple option (in devServer config)', () => {744 const config = createConfig(745 Object.assign({}, webpackConfig, {746 devServer: {747 open: true,748 openPage: ['/different/page', '/different/page2'],749 },750 }),751 argv,752 { port: 8080 }753 );754 expect(config).toMatchSnapshot();755 });756 it('useLocalIp option', () => {757 const config = createConfig(758 webpackConfig,759 Object.assign({}, argv, { useLocalIp: true }),760 { port: 8080 }761 );762 expect(config).toMatchSnapshot();763 });764 it('useLocalIp option (in devServer config)', () => {765 const config = createConfig(766 Object.assign({}, webpackConfig, {767 devServer: { useLocalIp: true },768 }),769 argv,770 { port: 8080 }771 );772 expect(config).toMatchSnapshot();773 });774 it('port option (same)', () => {775 const config = createConfig(776 webpackConfig,777 Object.assign({}, argv, { port: 9090 }),778 { port: 9090 }779 );780 expect(config).toMatchSnapshot();781 });782 it('port option (same) (string)', () => {783 const config = createConfig(784 webpackConfig,785 Object.assign({}, argv, { port: '9090' }),786 { port: '9090' }787 );788 expect(config).toMatchSnapshot();789 });790 it('port option (same) (null)', () => {791 const config = createConfig(792 webpackConfig,793 Object.assign({}, argv, { port: null }),794 { port: null }795 );796 expect(config).toMatchSnapshot();797 });798 it('port option (same) (undefined)', () => {799 const config = createConfig(800 webpackConfig,801 // eslint-disable-next-line no-undefined802 Object.assign({}, argv, { port: undefined }),803 // eslint-disable-next-line no-undefined804 { port: undefined }805 );806 expect(config).toMatchSnapshot();807 });808 it('port option (difference)', () => {809 const config = createConfig(810 webpackConfig,811 Object.assign({}, argv, { port: 7070 }),812 { port: 8080 }813 );814 expect(config).toMatchSnapshot();815 });816 it('use webpack stats', () => {817 expect(818 createConfig(webpackConfigNoStats, argv, { port: 8080 })819 ).toMatchSnapshot();820 expect(webpackConfigNoStats).toMatchSnapshot();821 });822 it('onListening option', () => {823 const config = createConfig(824 Object.assign({}, webpackConfig, {825 devServer: { onListening: () => {} },826 }),827 argv,828 { port: 8080 }829 );830 expect(config).toMatchSnapshot();831 });832 it('overlay option', () => {833 const config = createConfig(834 webpackConfig,835 Object.assign({}, argv, {836 overlay: true,837 }),838 { port: 8080 }839 );840 expect(config).toMatchSnapshot();841 });842 it('overlay option (in devServer config)', () => {843 const config = createConfig(844 Object.assign({}, webpackConfig, {845 devServer: { overlay: true },846 }),847 argv,848 { port: 8080 }849 );850 expect(config).toMatchSnapshot();851 });852 it('sockHost option', () => {853 const config = createConfig(854 webpackConfig,855 Object.assign({}, argv, {856 sockHost: true,857 }),858 { port: 8080 }859 );860 expect(config).toMatchSnapshot();861 });862 it('sockPath option', () => {863 const config = createConfig(864 webpackConfig,865 Object.assign({}, argv, {866 sockPath: 'path',867 }),868 { port: 8080 }869 );870 expect(config).toMatchSnapshot();871 });872 it('sockPort option', () => {873 const config = createConfig(874 webpackConfig,875 Object.assign({}, argv, {876 sockPort: 'port',877 }),878 { port: 8080 }879 );880 expect(config).toMatchSnapshot();881 });882 it('liveReload option', () => {883 const config = createConfig(884 webpackConfig,885 Object.assign({}, argv, {886 liveReload: false,887 }),888 { port: 8080 }889 );890 expect(config).toMatchSnapshot();891 });892 it('profile option', () => {893 const config = createConfig(894 webpackConfig,895 Object.assign({}, argv, {896 profile: 'profile',897 }),898 { port: 8080 }899 );900 expect(config).toMatchSnapshot();901 });...

Full Screen

Full Screen

TransformJSXToReactJSX-test.js

Source:TransformJSXToReactJSX-test.js Github

copy

Full Screen

...47 autoImport: 'namespace',48 importSource: 'foobar',49 }50 )51 ).toMatchSnapshot();52 });53 it('import source pragma overrides regular pragma', () => {54 expect(55 transform(56 `/** @jsxImportSource baz */57 var x = <div><span /></div>58 `,59 {60 autoImport: 'namespace',61 importSource: 'foobar',62 }63 )64 ).toMatchSnapshot();65 });66 it('multiple pragmas work', () => {67 expect(68 transform(69 `/** Some comment here70 * @jsxImportSource baz71 * @jsxAutoImport defaultExport72 */73 var x = <div><span /></div>74 `,75 {76 autoImport: 'namespace',77 importSource: 'foobar',78 }79 )80 ).toMatchSnapshot();81 });82 it('throws error when sourceType is module and autoImport is require', () => {83 const code = `var x = <div><span /></div>`;84 expect(() => {85 transform(code, {86 autoImport: 'require',87 });88 }).toThrow(89 'Babel `sourceType` must be set to `script` for autoImport ' +90 'to use `require` syntax. See Babel `sourceType` for details.\n' +91 codeFrame.codeFrameColumns(92 code,93 {start: {line: 1, column: 1}, end: {line: 1, column: 28}},94 {highlightCode: true}95 )96 );97 });98 it('throws error when sourceType is script and autoImport is not require', () => {99 const code = `var x = <div><span /></div>`;100 expect(() => {101 transform(102 code,103 {104 autoImport: 'namespace',105 },106 {sourceType: 'script'}107 );108 }).toThrow(109 'Babel `sourceType` must be set to `module` for autoImport ' +110 'to use `namespace` syntax. See Babel `sourceType` for details.\n' +111 codeFrame.codeFrameColumns(112 code,113 {start: {line: 1, column: 1}, end: {line: 1, column: 28}},114 {highlightCode: true}115 )116 );117 });118 it("auto import that doesn't exist should throw error", () => {119 const code = `var x = <div><span /></div>`;120 expect(() => {121 transform(code, {122 autoImport: 'foo',123 });124 }).toThrow(125 'autoImport must be one of the following: none, require, namespace, defaultExport, namedExports\n' +126 codeFrame.codeFrameColumns(127 code,128 {start: {line: 1, column: 1}, end: {line: 1, column: 28}},129 {highlightCode: true}130 )131 );132 });133 it('auto import can specify source', () => {134 expect(135 transform(`var x = <div><span /></div>`, {136 autoImport: 'namespace',137 importSource: 'foobar',138 })139 ).toMatchSnapshot();140 });141 it('auto import require', () => {142 expect(143 transform(144 `var x = (145 <>146 <div>147 <div key="1" />148 <div key="2" meow="wolf" />149 <div key="3" />150 <div {...props} key="4" />151 </div>152 </>153 );`,154 {155 autoImport: 'require',156 },157 {158 sourceType: 'script',159 }160 )161 ).toMatchSnapshot();162 });163 it('auto import namespace', () => {164 expect(165 transform(166 `var x = (167 <>168 <div>169 <div key="1" />170 <div key="2" meow="wolf" />171 <div key="3" />172 <div {...props} key="4" />173 </div>174 </>175 );`,176 {177 autoImport: 'namespace',178 }179 )180 ).toMatchSnapshot();181 });182 it('auto import default', () => {183 expect(184 transform(185 `var x = (186 <>187 <div>188 <div key="1" />189 <div key="2" meow="wolf" />190 <div key="3" />191 <div {...props} key="4" />192 </div>193 </>194 );`,195 {196 autoImport: 'defaultExport',197 }198 )199 ).toMatchSnapshot();200 });201 it('auto import named exports', () => {202 expect(203 transform(204 `var x = (205 <>206 <div>207 <div key="1" />208 <div key="2" meow="wolf" />209 <div key="3" />210 <div {...props} key="4" />211 </div>212 </>213 );`,214 {215 autoImport: 'namedExports',216 }217 )218 ).toMatchSnapshot();219 });220 it('auto import with no JSX', () => {221 expect(222 transform(223 `var foo = "<div></div>"`,224 {225 autoImport: 'require',226 },227 {228 sourceType: 'script',229 }230 )231 ).toMatchSnapshot();232 });233 it('complicated scope require', () => {234 expect(235 transform(236 `237 const Bar = () => {238 const Foo = () => {239 const Component = ({thing, ..._react}) => {240 if (!thing) {241 var _react2 = "something useless";242 var b = _react3();243 var c = _react5();244 var jsx = 1;245 var _jsx = 2;246 return <div />;247 };248 return <span />;249 };250 }251 }252 `,253 {254 autoImport: 'require',255 },256 {257 sourceType: 'script',258 }259 )260 ).toMatchSnapshot();261 });262 it('complicated scope named exports', () => {263 expect(264 transform(265 `266 const Bar = () => {267 const Foo = () => {268 const Component = ({thing, ..._react}) => {269 if (!thing) {270 var _react2 = "something useless";271 var b = _react3();272 var jsx = 1;273 var _jsx = 2;274 return <div />;275 };276 return <span />;277 };278 }279 }280 `,281 {282 autoImport: 'namedExports',283 }284 )285 ).toMatchSnapshot();286 });287 it('auto import in dev', () => {288 expect(289 transform(290 `var x = (291 <>292 <div>293 <div key="1" />294 <div key="2" meow="wolf" />295 <div key="3" />296 <div {...props} key="4" />297 </div>298 </>299 );`,300 {301 autoImport: 'namedExports',302 development: true,303 }304 )305 ).toMatchSnapshot();306 });307 it('auto import none', () => {308 expect(309 transform(310 `var x = (311 <>312 <div>313 <div key="1" />314 <div key="2" meow="wolf" />315 <div key="3" />316 <div {...props} key="4" />317 </div>318 </>319 );`,320 {321 autoImport: 'none',322 }323 )324 ).toMatchSnapshot();325 });326 it('auto import undefined', () => {327 expect(328 transform(329 `var x = (330 <>331 <div>332 <div key="1" />333 <div key="2" meow="wolf" />334 <div key="3" />335 <div {...props} key="4" />336 </div>337 </>338 );`339 )340 ).toMatchSnapshot();341 });342 it('auto import with namespaces already defined', () => {343 expect(344 transform(345 `346 import * as _react from "foo";347 const react = _react(1);348 const _react1 = react;349 const _react2 = react;350 var x = (351 <div>352 <div key="1" />353 <div key="2" meow="wolf" />354 <div key="3" />355 <div {...props} key="4" />356 </div>357 );`,358 {359 autoImport: 'namespace',360 }361 )362 ).toMatchSnapshot();363 });364 it('auto import with react already defined', () => {365 expect(366 transform(367 `368 import * as react from "react";369 var y = react.createElement("div", {foo: 1});370 var x = (371 <div>372 <div key="1" />373 <div key="2" meow="wolf" />374 <div key="3" />375 <div {...props} key="4" />376 </div>377 );`,378 {379 autoImport: 'namespace',380 }381 )382 ).toMatchSnapshot();383 });384 it('fragment with no children', () => {385 expect(transform(`var x = <></>`)).toMatchSnapshot();386 });387 it('fragments', () => {388 expect(transform(`var x = <><div /></>`)).toMatchSnapshot();389 });390 it('fragments to set keys', () => {391 expect(392 transform(`var x = <React.Fragment key="foo"></React.Fragment>`)393 ).toMatchSnapshot();394 });395 it('React.fragment to set keys and source', () => {396 expect(397 transform(`var x = <React.Fragment key='foo'></React.Fragment>`, {398 development: true,399 })400 ).toMatchSnapshot();401 });402 it('fragments in dev mode (no key and source)', () => {403 expect(404 transform(`var x = <><div /></>`, {405 development: true,406 })407 ).toMatchSnapshot();408 });409 it('nonStatic children', () => {410 expect(411 transform(412 `var x = (413 <div>414 {[<span key={'0'} />, <span key={'1'} />]}415 </div>416 );417 `,418 {419 development: true,420 }421 )422 ).toMatchSnapshot();423 });424 it('static children', () => {425 expect(426 transform(427 `var x = (428 <div>429 <span />430 {[<span key={'0'} />, <span key={'1'} />]}431 </div>432 );433 `,434 {435 development: true,436 }437 )438 ).toMatchSnapshot();439 });440 it('uses jsxDEV instead of jsx in dev mode', () => {441 expect(442 transform(`var x = <span propOne="one">Hi</span>`, {development: true})443 ).toMatchSnapshot();444 });445 it('properly passes in source and self', () => {446 expect(447 transform(`var x = <div />;`, {development: true})448 ).toMatchSnapshot();449 });450 it('should properly handle potentially null variables', () => {451 expect(452 transform(`453 var foo = null;454 var x = <div {...foo} />;455 `)456 ).toMatchSnapshot();457 });458 it('properly handles keys', () => {459 expect(460 transform(`var x = (461 <div>462 <div key="1" />463 <div key="2" meow="wolf" />464 <div key="3" />465 </div>466 );`)467 ).toMatchSnapshot();468 });469 it('uses createElement when the key comes after a spread', () => {470 expect(471 transform(`var x = (472 <div {...props} key="1" foo="bar" />473 );`)474 ).toMatchSnapshot();475 });476 it('uses jsx when the key comes before a spread', () => {477 expect(478 transform(`var x = (479 <div key="1" {...props} foo="bar" />480 );`)481 ).toMatchSnapshot();482 });483 it('should properly handle comments adjacent to children', () => {484 expect(485 transform(`486 var x = (487 <div>488 {/* A comment at the beginning */}489 {/* A second comment at the beginning */}490 <span>491 {/* A nested comment */}492 </span>493 {/* A sandwiched comment */}494 <br />495 {/* A comment at the end */}496 {/* A second comment at the end */}497 </div>498 );499 `)500 ).toMatchSnapshot();501 });502 it('adds appropriate new lines when using spread attribute', () => {503 expect(transform(`<Component {...props} sound="moo" />`)).toMatchSnapshot();504 });505 it('arrow functions', () => {506 expect(507 transform(`508 var foo = function () {509 return () => <this />;510 };511 var bar = function () {512 return () => <this.foo />;513 };514 `)515 ).toMatchSnapshot();516 });517 it('assignment', () => {518 expect(519 transform(`var div = <Component {...props} foo="bar" />`)520 ).toMatchSnapshot();521 });522 it('concatenates adjacent string literals', () => {523 expect(524 transform(`525 var x =526 <div>527 foo528 {"bar"}529 baz530 <div>531 buz532 bang533 </div>534 qux535 {null}536 quack537 </div>538 `)539 ).toMatchSnapshot();540 });541 it('should allow constructor as prop', () => {542 expect(transform(`<Component constructor="foo" />;`)).toMatchSnapshot();543 });544 it('should allow deeper js namespacing', () => {545 expect(546 transform(`<Namespace.DeepNamespace.Component />;`)547 ).toMatchSnapshot();548 });549 it('should allow elements as attributes', () => {550 expect(transform(`<div attr=<div /> />`)).toMatchSnapshot();551 });552 it('should allow js namespacing', () => {553 expect(transform(`<Namespace.Component />;`)).toMatchSnapshot();554 });555 it('should allow nested fragments', () => {556 expect(557 transform(`558 <div>559 < >560 <>561 <span>Hello</span>562 <span>world</span>563 </>564 <>565 <span>Goodbye</span>566 <span>world</span>567 </>568 </>569 </div>570 `)571 ).toMatchSnapshot();572 });573 it('should avoid wrapping in extra parens if not needed', () => {574 expect(575 transform(`576 var x = <div>577 <Component />578 </div>;579 var x = <div>580 {props.children}581 </div>;582 var x = <Composite>583 {props.children}584 </Composite>;585 var x = <Composite>586 <Composite2 />587 </Composite>;588 `)589 ).toMatchSnapshot();590 });591 it('should convert simple tags', () => {592 expect(transform(`var x = <div></div>;`)).toMatchSnapshot();593 });594 it('should convert simple text', () => {595 expect(transform(`var x = <div>text</div>;`)).toMatchSnapshot();596 });597 it('should disallow spread children', () => {598 let _error;599 const code = `<div>{...children}</div>;`;600 try {601 transform(code);602 } catch (error) {603 _error = error;604 }605 expect(_error).toEqual(606 new SyntaxError(607 'unknown: Spread children are not supported in React.' +608 '\n' +609 codeFrame.codeFrameColumns(610 code,611 {start: {line: 1, column: 6}, end: {line: 1, column: 19}},612 {highlightCode: true}613 )614 )615 );616 });617 it('should escape xhtml jsxattribute', () => {618 expect(619 transform(`620 <div id="wôw" />;621 <div id="\w" />;622 <div id="w &lt; w" />;623 `)624 ).toMatchSnapshot();625 });626 it('should escape xhtml jsxtext', () => {627 /* eslint-disable no-irregular-whitespace */628 expect(629 transform(`630 <div>wow</div>;631 <div>wôw</div>;632 <div>w & w</div>;633 <div>w &amp; w</div>;634 <div>w &nbsp; w</div>;635 <div>this should not parse as unicode: \u00a0</div>;636 <div>this should parse as nbsp:   </div>;637 <div>this should parse as unicode: {'\u00a0 '}</div>;638 <div>w &lt; w</div>;639 `)640 ).toMatchSnapshot();641 /*eslint-enable */642 });643 it('should handle attributed elements', () => {644 expect(645 transform(`646 var HelloMessage = React.createClass({647 render: function() {648 return <div>Hello {this.props.name}</div>;649 }650 });651 React.render(<HelloMessage name={652 <span>653 Sebastian654 </span>655 } />, mountNode);656 `)657 ).toMatchSnapshot();658 });659 it('should handle has own property correctly', () => {660 expect(661 transform(`<hasOwnProperty>testing</hasOwnProperty>;`)662 ).toMatchSnapshot();663 });664 it('should have correct comma in nested children', () => {665 expect(666 transform(`667 var x = <div>668 <div><br /></div>669 <Component>{foo}<br />{bar}</Component>670 <br />671 </div>;672 `)673 ).toMatchSnapshot();674 });675 it('should insert commas after expressions before whitespace', () => {676 expect(677 transform(`678 var x =679 <div680 attr1={681 "foo" + "bar"682 }683 attr2={684 "foo" + "bar" +685 "baz" + "bug"686 }687 attr3={688 "foo" + "bar" +689 "baz" + "bug"690 }691 attr4="baz">692 </div>693 `)694 ).toMatchSnapshot();695 });696 it('should not add quotes to identifier names', () => {697 expect(698 transform(`var e = <F aaa new const var default foo-bar/>;`)699 ).toMatchSnapshot();700 });701 it('should not strip nbsp even couple with other whitespace', () => {702 expect(transform(`<div>&nbsp; </div>;`)).toMatchSnapshot();703 });704 it('should not strip tags with a single child of nbsp', () => {705 expect(transform(`<div>&nbsp;</div>;`)).toMatchSnapshot();706 });707 it('should properly handle comments between props', () => {708 expect(709 transform(`710 var x = (711 <div712 /* a multi-line713 comment */714 attr1="foo">715 <span // a double-slash comment716 attr2="bar"717 />718 </div>719 );720 `)721 ).toMatchSnapshot();722 });723 it('should quote jsx attributes', () => {724 expect(725 transform(`<button data-value='a value'>Button</button>`)726 ).toMatchSnapshot();727 });728 it('should support xml namespaces if flag', () => {729 expect(730 transform('<f:image n:attr />', {throwIfNamespace: false})731 ).toMatchSnapshot();732 });733 it('should throw error namespaces if not flag', () => {734 let _error;735 const code = `<f:image />`;736 try {737 transform(code);738 } catch (error) {739 _error = error;740 }741 expect(_error).toEqual(742 new SyntaxError(743 "unknown: Namespace tags are not supported by default. React's " +744 "JSX doesn't support namespace tags. You can turn on the " +745 "'throwIfNamespace' flag to bypass this warning." +746 '\n' +747 codeFrame.codeFrameColumns(748 code,749 {start: {line: 1, column: 2}, end: {line: 1, column: 9}},750 {highlightCode: true}751 )752 )753 );754 });755 it('should transform known hyphenated tags', () => {756 expect(transform(`<font-face />`)).toMatchSnapshot();757 });758 it('wraps props in react spread for first spread attributes', () => {759 expect(transform(`<Component {...x} y={2} z />`)).toMatchSnapshot();760 });761 it('wraps props in react spread for last spread attributes', () => {762 expect(transform(`<Component y={2} z { ... x } />`)).toMatchSnapshot();763 });764 it('wraps props in react spread for middle spread attributes', () => {765 expect(transform(`<Component y={2} { ... x } z />`)).toMatchSnapshot();766 });767 it('useBuiltIns false uses extend instead of Object.assign', () => {768 expect(769 transform(`<Component y={2} {...x} />`, {useBuiltIns: false})770 ).toMatchSnapshot();771 });772 it('duplicate children prop should transform into sequence expression with actual children', () => {773 expect(774 transform(`<Component children={1}>2</Component>`)775 ).toMatchSnapshot();776 });777 it('duplicate children prop should transform into sequence expression with next prop', () => {778 expect(779 transform(`<Component children={1} foo={3}>2</Component>`)780 ).toMatchSnapshot();781 });782 it('duplicate children props should transform into sequence expression with next prop', () => {783 expect(784 transform(`<Component children={1} children={4} foo={3}>2</Component>`)785 ).toMatchSnapshot();786 });787 it('duplicate children prop should transform into sequence expression with spread', () => {788 expect(789 transform(`<Component children={1} {...x}>2</Component>`)790 ).toMatchSnapshot();791 });...

Full Screen

Full Screen

treeContext-test.js

Source:treeContext-test.js Github

copy

Full Screen

...73 const Child = () => null;74 utils.act(() =>75 ReactDOM.render(<Grandparent />, document.createElement('div')),76 );77 expect(store).toMatchSnapshot('0: mount');78 let renderer;79 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));80 expect(state).toMatchSnapshot('1: initial state');81 utils.act(() => dispatch({type: 'SELECT_NEXT_ELEMENT_IN_TREE'}));82 utils.act(() => renderer.update(<Contexts />));83 expect(state).toMatchSnapshot('2: select first element');84 while (85 state.selectedElementIndex !== null &&86 state.selectedElementIndex < store.numElements - 187 ) {88 const index = ((state.selectedElementIndex: any): number);89 utils.act(() => dispatch({type: 'SELECT_NEXT_ELEMENT_IN_TREE'}));90 utils.act(() => renderer.update(<Contexts />));91 expect(state).toMatchSnapshot(`3: select element after (${index})`);92 }93 while (94 state.selectedElementIndex !== null &&95 state.selectedElementIndex > 096 ) {97 const index = ((state.selectedElementIndex: any): number);98 utils.act(() => dispatch({type: 'SELECT_PREVIOUS_ELEMENT_IN_TREE'}));99 utils.act(() => renderer.update(<Contexts />));100 expect(state).toMatchSnapshot(`4: select element before (${index})`);101 }102 utils.act(() => dispatch({type: 'SELECT_PREVIOUS_ELEMENT_IN_TREE'}));103 utils.act(() => renderer.update(<Contexts />));104 expect(state).toMatchSnapshot('5: select previous wraps around to last');105 utils.act(() => dispatch({type: 'SELECT_NEXT_ELEMENT_IN_TREE'}));106 utils.act(() => renderer.update(<Contexts />));107 expect(state).toMatchSnapshot('6: select next wraps around to first');108 });109 it('should select child elements', () => {110 const Grandparent = () => (111 <React.Fragment>112 <Parent />113 <Parent />114 </React.Fragment>115 );116 const Parent = () => (117 <React.Fragment>118 <Child />119 <Child />120 </React.Fragment>121 );122 const Child = () => null;123 utils.act(() =>124 ReactDOM.render(<Grandparent />, document.createElement('div')),125 );126 expect(store).toMatchSnapshot('0: mount');127 let renderer;128 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));129 expect(state).toMatchSnapshot('1: initial state');130 utils.act(() => dispatch({type: 'SELECT_ELEMENT_AT_INDEX', payload: 0}));131 utils.act(() => renderer.update(<Contexts />));132 expect(state).toMatchSnapshot('2: select first element');133 utils.act(() => dispatch({type: 'SELECT_CHILD_ELEMENT_IN_TREE'}));134 utils.act(() => renderer.update(<Contexts />));135 expect(state).toMatchSnapshot('3: select Parent');136 utils.act(() => dispatch({type: 'SELECT_CHILD_ELEMENT_IN_TREE'}));137 utils.act(() => renderer.update(<Contexts />));138 expect(state).toMatchSnapshot('4: select Child');139 const previousState = state;140 // There are no more children to select, so this should be a no-op141 utils.act(() => dispatch({type: 'SELECT_CHILD_ELEMENT_IN_TREE'}));142 utils.act(() => renderer.update(<Contexts />));143 expect(state).toEqual(previousState);144 });145 it('should select parent elements and then collapse', () => {146 const Grandparent = () => (147 <React.Fragment>148 <Parent />149 <Parent />150 </React.Fragment>151 );152 const Parent = () => (153 <React.Fragment>154 <Child />155 <Child />156 </React.Fragment>157 );158 const Child = () => null;159 utils.act(() =>160 ReactDOM.render(<Grandparent />, document.createElement('div')),161 );162 expect(store).toMatchSnapshot('0: mount');163 let renderer;164 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));165 expect(state).toMatchSnapshot('1: initial state');166 const lastChildID = store.getElementIDAtIndex(store.numElements - 1);167 utils.act(() =>168 dispatch({type: 'SELECT_ELEMENT_BY_ID', payload: lastChildID}),169 );170 utils.act(() => renderer.update(<Contexts />));171 expect(state).toMatchSnapshot('2: select last child');172 utils.act(() => dispatch({type: 'SELECT_PARENT_ELEMENT_IN_TREE'}));173 utils.act(() => renderer.update(<Contexts />));174 expect(state).toMatchSnapshot('3: select Parent');175 utils.act(() => dispatch({type: 'SELECT_PARENT_ELEMENT_IN_TREE'}));176 utils.act(() => renderer.update(<Contexts />));177 expect(state).toMatchSnapshot('4: select Grandparent');178 const previousState = state;179 // There are no more ancestors to select, so this should be a no-op180 utils.act(() => dispatch({type: 'SELECT_PARENT_ELEMENT_IN_TREE'}));181 utils.act(() => renderer.update(<Contexts />));182 expect(state).toEqual(previousState);183 });184 it('should clear selection if the selected element is unmounted', async done => {185 const Grandparent = props => props.children || null;186 const Parent = props => props.children || null;187 const Child = () => null;188 const container = document.createElement('div');189 utils.act(() =>190 ReactDOM.render(191 <Grandparent>192 <Parent>193 <Child />194 <Child />195 </Parent>196 </Grandparent>,197 container,198 ),199 );200 expect(store).toMatchSnapshot('0: mount');201 let renderer;202 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));203 expect(state).toMatchSnapshot('1: initial state');204 utils.act(() => dispatch({type: 'SELECT_ELEMENT_AT_INDEX', payload: 3}));205 utils.act(() => renderer.update(<Contexts />));206 expect(state).toMatchSnapshot('2: select second child');207 await utils.actAsync(() =>208 ReactDOM.render(209 <Grandparent>210 <Parent />211 </Grandparent>,212 container,213 ),214 );215 expect(state).toMatchSnapshot(216 '3: remove children (parent should now be selected)',217 );218 await utils.actAsync(() => ReactDOM.unmountComponentAtNode(container));219 expect(state).toMatchSnapshot(220 '4: unmount root (nothing should be selected)',221 );222 done();223 });224 });225 describe('search state', () => {226 it('should find elements matching search text', () => {227 const Foo = () => null;228 const Bar = () => null;229 const Baz = () => null;230 const Qux = () => null;231 Qux.displayName = `withHOC(${Qux.name})`;232 utils.act(() =>233 ReactDOM.render(234 <React.Fragment>235 <Foo />236 <Bar />237 <Baz />238 <Qux />239 </React.Fragment>,240 document.createElement('div'),241 ),242 );243 expect(store).toMatchSnapshot('0: mount');244 let renderer;245 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));246 expect(state).toMatchSnapshot('1: initial state');247 // NOTE: multi-match248 utils.act(() => dispatch({type: 'SET_SEARCH_TEXT', payload: 'ba'}));249 utils.act(() => renderer.update(<Contexts />));250 expect(state).toMatchSnapshot('2: search for "ba"');251 // NOTE: single match252 utils.act(() => dispatch({type: 'SET_SEARCH_TEXT', payload: 'f'}));253 utils.act(() => renderer.update(<Contexts />));254 expect(state).toMatchSnapshot('3: search for "f"');255 // NOTE: no match256 utils.act(() => dispatch({type: 'SET_SEARCH_TEXT', payload: 'y'}));257 utils.act(() => renderer.update(<Contexts />));258 expect(state).toMatchSnapshot('4: search for "y"');259 // NOTE: HOC match260 utils.act(() => dispatch({type: 'SET_SEARCH_TEXT', payload: 'w'}));261 utils.act(() => renderer.update(<Contexts />));262 expect(state).toMatchSnapshot('5: search for "w"');263 });264 it('should select the next and previous items within the search results', () => {265 const Foo = () => null;266 const Bar = () => null;267 const Baz = () => null;268 utils.act(() =>269 ReactDOM.render(270 <React.Fragment>271 <Foo />272 <Baz />273 <Bar />274 <Baz />275 </React.Fragment>,276 document.createElement('div'),277 ),278 );279 expect(store).toMatchSnapshot('0: mount');280 let renderer;281 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));282 expect(state).toMatchSnapshot('1: initial state');283 utils.act(() => dispatch({type: 'SET_SEARCH_TEXT', payload: 'ba'}));284 utils.act(() => renderer.update(<Contexts />));285 expect(state).toMatchSnapshot('2: search for "ba"');286 utils.act(() => dispatch({type: 'GO_TO_NEXT_SEARCH_RESULT'}));287 utils.act(() => renderer.update(<Contexts />));288 expect(state).toMatchSnapshot('3: go to second result');289 utils.act(() => dispatch({type: 'GO_TO_NEXT_SEARCH_RESULT'}));290 utils.act(() => renderer.update(<Contexts />));291 expect(state).toMatchSnapshot('4: go to third result');292 utils.act(() => dispatch({type: 'GO_TO_PREVIOUS_SEARCH_RESULT'}));293 utils.act(() => renderer.update(<Contexts />));294 expect(state).toMatchSnapshot('5: go to second result');295 utils.act(() => dispatch({type: 'GO_TO_PREVIOUS_SEARCH_RESULT'}));296 utils.act(() => renderer.update(<Contexts />));297 expect(state).toMatchSnapshot('6: go to first result');298 utils.act(() => dispatch({type: 'GO_TO_PREVIOUS_SEARCH_RESULT'}));299 utils.act(() => renderer.update(<Contexts />));300 expect(state).toMatchSnapshot('7: wrap to last result');301 utils.act(() => dispatch({type: 'GO_TO_NEXT_SEARCH_RESULT'}));302 utils.act(() => renderer.update(<Contexts />));303 expect(state).toMatchSnapshot('8: wrap to first result');304 });305 it('should add newly mounted elements to the search results set if they match the current text', async done => {306 const Foo = () => null;307 const Bar = () => null;308 const Baz = () => null;309 const container = document.createElement('div');310 utils.act(() =>311 ReactDOM.render(312 <React.Fragment>313 <Foo />314 <Bar />315 </React.Fragment>,316 container,317 ),318 );319 expect(store).toMatchSnapshot('0: mount');320 let renderer;321 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));322 expect(state).toMatchSnapshot('1: initial state');323 utils.act(() => dispatch({type: 'SET_SEARCH_TEXT', payload: 'ba'}));324 utils.act(() => renderer.update(<Contexts />));325 expect(state).toMatchSnapshot('2: search for "ba"');326 await utils.actAsync(() =>327 ReactDOM.render(328 <React.Fragment>329 <Foo />330 <Bar />331 <Baz />332 </React.Fragment>,333 container,334 ),335 );336 utils.act(() => renderer.update(<Contexts />));337 expect(state).toMatchSnapshot('3: mount Baz');338 done();339 });340 it('should remove unmounted elements from the search results set', async done => {341 const Foo = () => null;342 const Bar = () => null;343 const Baz = () => null;344 const container = document.createElement('div');345 utils.act(() =>346 ReactDOM.render(347 <React.Fragment>348 <Foo />349 <Bar />350 <Baz />351 </React.Fragment>,352 container,353 ),354 );355 expect(store).toMatchSnapshot('0: mount');356 let renderer;357 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));358 expect(state).toMatchSnapshot('1: initial state');359 utils.act(() => dispatch({type: 'SET_SEARCH_TEXT', payload: 'ba'}));360 utils.act(() => renderer.update(<Contexts />));361 expect(state).toMatchSnapshot('2: search for "ba"');362 utils.act(() => dispatch({type: 'GO_TO_NEXT_SEARCH_RESULT'}));363 utils.act(() => renderer.update(<Contexts />));364 expect(state).toMatchSnapshot('3: go to second result');365 await utils.actAsync(() =>366 ReactDOM.render(367 <React.Fragment>368 <Foo />369 <Bar />370 </React.Fragment>,371 container,372 ),373 );374 utils.act(() => renderer.update(<Contexts />));375 expect(state).toMatchSnapshot('4: unmount Baz');376 done();377 });378 });379 describe('owners state', () => {380 it('should support entering and existing the owners tree view', () => {381 const Grandparent = () => <Parent />;382 const Parent = () => (383 <React.Fragment>384 <Child />385 <Child />386 </React.Fragment>387 );388 const Child = () => null;389 utils.act(() =>390 ReactDOM.render(<Grandparent />, document.createElement('div')),391 );392 expect(store).toMatchSnapshot('0: mount');393 let renderer;394 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));395 expect(state).toMatchSnapshot('1: initial state');396 const parentID = ((store.getElementIDAtIndex(1): any): number);397 utils.act(() => dispatch({type: 'SELECT_OWNER', payload: parentID}));398 utils.act(() => renderer.update(<Contexts />));399 expect(state).toMatchSnapshot('2: parent owners tree');400 utils.act(() => dispatch({type: 'RESET_OWNER_STACK'}));401 utils.act(() => renderer.update(<Contexts />));402 expect(state).toMatchSnapshot('3: final state');403 });404 it('should remove an element from the owners list if it is unmounted', async done => {405 const Grandparent = ({count}) => <Parent count={count} />;406 const Parent = ({count}) =>407 new Array(count).fill(true).map((_, index) => <Child key={index} />);408 const Child = () => null;409 const container = document.createElement('div');410 utils.act(() => ReactDOM.render(<Grandparent count={2} />, container));411 expect(store).toMatchSnapshot('0: mount');412 let renderer;413 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));414 expect(state).toMatchSnapshot('1: initial state');415 const parentID = ((store.getElementIDAtIndex(1): any): number);416 utils.act(() => dispatch({type: 'SELECT_OWNER', payload: parentID}));417 utils.act(() => renderer.update(<Contexts />));418 expect(state).toMatchSnapshot('2: parent owners tree');419 await utils.actAsync(() =>420 ReactDOM.render(<Grandparent count={1} />, container),421 );422 expect(state).toMatchSnapshot('3: remove second child');423 await utils.actAsync(() =>424 ReactDOM.render(<Grandparent count={0} />, container),425 );426 expect(state).toMatchSnapshot('4: remove first child');427 done();428 });429 it('should exit the owners list if the current owner is unmounted', async done => {430 const Parent = props => props.children || null;431 const Child = () => null;432 const container = document.createElement('div');433 utils.act(() =>434 ReactDOM.render(435 <Parent>436 <Child />437 </Parent>,438 container,439 ),440 );441 expect(store).toMatchSnapshot('0: mount');442 let renderer;443 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));444 expect(state).toMatchSnapshot('1: initial state');445 const childID = ((store.getElementIDAtIndex(1): any): number);446 utils.act(() => dispatch({type: 'SELECT_OWNER', payload: childID}));447 utils.act(() => renderer.update(<Contexts />));448 expect(state).toMatchSnapshot('2: child owners tree');449 await utils.actAsync(() => ReactDOM.render(<Parent />, container));450 expect(state).toMatchSnapshot('3: remove child');451 const parentID = ((store.getElementIDAtIndex(0): any): number);452 utils.act(() => dispatch({type: 'SELECT_OWNER', payload: parentID}));453 utils.act(() => renderer.update(<Contexts />));454 expect(state).toMatchSnapshot('4: parent owners tree');455 await utils.actAsync(() => ReactDOM.unmountComponentAtNode(container));456 expect(state).toMatchSnapshot('5: unmount root');457 done();458 });459 // This tests ensures support for toggling Suspense boundaries outside of the active owners list.460 it('should exit the owners list if an element outside the list is selected', () => {461 const Grandchild = () => null;462 const Child = () => (463 <React.Suspense fallback="Loading">464 <Grandchild />465 </React.Suspense>466 );467 const Parent = () => (468 <React.Suspense fallback="Loading">469 <Child />470 </React.Suspense>471 );472 const container = document.createElement('div');473 utils.act(() => ReactDOM.render(<Parent />, container));474 expect(store).toMatchSnapshot('0: mount');475 let renderer;476 utils.act(() => (renderer = TestRenderer.create(<Contexts />)));477 expect(state).toMatchSnapshot('1: initial state');478 const outerSuspenseID = ((store.getElementIDAtIndex(1): any): number);479 const childID = ((store.getElementIDAtIndex(2): any): number);480 const innerSuspenseID = ((store.getElementIDAtIndex(3): any): number);481 utils.act(() => dispatch({type: 'SELECT_OWNER', payload: childID}));482 utils.act(() => renderer.update(<Contexts />));483 expect(state).toMatchSnapshot('2: child owners tree');484 // Toggling a Suspense boundary inside of the flat list should update selected index485 utils.act(() =>486 dispatch({type: 'SELECT_ELEMENT_BY_ID', payload: innerSuspenseID}),487 );488 utils.act(() => renderer.update(<Contexts />));489 expect(state).toMatchSnapshot('3: child owners tree');490 // Toggling a Suspense boundary outside of the flat list should exit owners list and update index491 utils.act(() =>492 dispatch({type: 'SELECT_ELEMENT_BY_ID', payload: outerSuspenseID}),493 );494 utils.act(() => renderer.update(<Contexts />));495 expect(state).toMatchSnapshot('4: main tree');496 });497 });...

Full Screen

Full Screen

Array.test.js

Source:Array.test.js Github

copy

Full Screen

...22 expect(normalizeBad).toThrowErrorMatchingSnapshot();23 });24 test(`normalizes plain arrays as shorthand for ${schema.Array.name}`, () => {25 class User extends IDEntity {}26 expect(normalize([{ id: '1' }, { id: '2' }], [User])).toMatchSnapshot();27 });28 test('throws an error if created with more than one schema', () => {29 class User extends IDEntity {}30 class Cat extends IDEntity {}31 expect(() => normalize([{ id: '1' }], [Cat, User])).toThrow();32 });33 test('passes its parent to its children when normalizing', () => {34 class Child extends IDEntity {35 content = '';36 static fromJS(entity, parent, key) {37 return super.fromJS({38 ...entity,39 parentId: parent.id,40 parentKey: key,41 });42 }43 }44 class Parent extends IDEntity {45 content = '';46 children = [];47 static schema = {48 children: [Child],49 };50 }51 expect(52 normalize(53 {54 id: '1',55 content: 'parent',56 children: [{ id: 4, content: 'child' }],57 },58 Parent,59 ),60 ).toMatchSnapshot();61 });62 test('normalizes Objects using their values', () => {63 class User extends IDEntity {}64 expect(65 normalize({ foo: { id: '1' }, bar: { id: '2' } }, [User]),66 ).toMatchSnapshot();67 });68 });69 describe('Class', () => {70 class Cats extends IDEntity {}71 test('normalizes a single entity', () => {72 const listSchema = new schema.Array(Cats);73 expect(74 normalize([{ id: '1' }, { id: '2' }], listSchema),75 ).toMatchSnapshot();76 });77 test('normalizes multiple entities', () => {78 const inferSchemaFn = jest.fn(79 (input, parent, key) => input.type || 'dogs',80 );81 class Person extends IDEntity {}82 const listSchema = new schema.Array(83 {84 Cat: Cats,85 people: Person,86 },87 inferSchemaFn,88 );89 expect(90 normalize(91 [92 { type: 'Cat', id: '123' },93 { type: 'people', id: '123' },94 { id: '789', name: 'fido' },95 { type: 'Cat', id: '456' },96 ],97 listSchema,98 ),99 ).toMatchSnapshot();100 expect(inferSchemaFn.mock.calls).toMatchSnapshot();101 });102 test('normalizes Objects using their values', () => {103 class User extends IDEntity {}104 const users = new schema.Array(User);105 expect(106 normalize({ foo: { id: '1' }, bar: { id: '2' } }, users),107 ).toMatchSnapshot();108 });109 test('filters out undefined and null normalized values', () => {110 class User extends IDEntity {}111 const users = new schema.Array(User);112 expect(113 normalize([undefined, { id: '123' }, null], users),114 ).toMatchSnapshot();115 });116 });117});118describe(`${schema.Array.name} denormalization`, () => {119 describe('Object', () => {120 test('denormalizes a single entity', () => {121 class Cat extends IDEntity {}122 const entities = {123 Cat: {124 '1': { id: '1', name: 'Milo' },125 '2': { id: '2', name: 'Jake' },126 },127 };128 expect(denormalize(['1', '2'], [Cat], entities)).toMatchSnapshot();129 expect(130 denormalize(['1', '2'], [Cat], fromJS(entities)),131 ).toMatchSnapshot();132 });133 test('denormalizes plain arrays with nothing inside', () => {134 class User extends IDEntity {}135 const entities = {136 User: {137 '1': { id: '1', name: 'Jane' },138 },139 };140 expect(141 denormalize({ user: '1' }, { user: User, tacos: [] }, entities),142 ).toMatchSnapshot();143 expect(144 denormalize({ user: '1' }, { user: User, tacos: [] }, fromJS(entities)),145 ).toMatchSnapshot();146 expect(147 denormalize(148 fromJS({ user: '1' }),149 { user: User, tacos: [] },150 fromJS(entities),151 ),152 ).toMatchSnapshot();153 expect(154 denormalize(155 { user: '1', tacos: [] },156 { user: User, tacos: [] },157 entities,158 ),159 ).toMatchSnapshot();160 expect(161 denormalize(162 { user: '1', tacos: [] },163 { user: User, tacos: [] },164 fromJS(entities),165 ),166 ).toMatchSnapshot();167 expect(168 denormalize(169 fromJS({ user: '1', tacos: [] }),170 { user: User, tacos: [] },171 fromJS(entities),172 ),173 ).toMatchSnapshot();174 });175 test('denormalizes plain arrays with plain object inside', () => {176 class User extends IDEntity {}177 const entities = {178 User: {179 '1': { id: '1', name: 'Jane' },180 },181 };182 expect(183 denormalize(184 { user: '1' },185 { user: User, tacos: [{ next: '' }] },186 entities,187 ),188 ).toMatchSnapshot();189 expect(190 denormalize(191 { user: '1' },192 { user: User, tacos: [{ next: '' }] },193 fromJS(entities),194 ),195 ).toMatchSnapshot();196 expect(197 denormalize(198 fromJS({ user: '1' }),199 { user: User, tacos: [{ next: '' }] },200 fromJS(entities),201 ),202 ).toMatchSnapshot();203 expect(204 denormalize(205 { user: '1', tacos: [] },206 { user: User, tacos: [{ next: '' }] },207 entities,208 ),209 ).toMatchSnapshot();210 expect(211 denormalize(212 { user: '1', tacos: [] },213 { user: User, tacos: [{ next: '' }] },214 fromJS(entities),215 ),216 ).toMatchSnapshot();217 expect(218 denormalize(219 fromJS({ user: '1', tacos: [] }),220 { user: User, tacos: [{ next: '' }] },221 fromJS(entities),222 ),223 ).toMatchSnapshot();224 });225 test('denormalizes nested in object', () => {226 class Cat extends IDEntity {}227 const catSchema = { results: [Cat] };228 const entities = {229 Cat: {230 '1': { id: '1', name: 'Milo' },231 '2': { id: '2', name: 'Jake' },232 },233 };234 expect(235 denormalize({ results: ['1', '2'] }, catSchema, entities),236 ).toMatchSnapshot();237 expect(238 denormalize({ results: ['1', '2'] }, catSchema, fromJS(entities)),239 ).toMatchSnapshot();240 });241 test('denormalizes nested in object with primitive', () => {242 class Cat extends IDEntity {}243 const catSchema = { results: [Cat], nextPage: '' };244 const entities = {245 Cat: {246 '1': { id: '1', name: 'Milo' },247 '2': { id: '2', name: 'Jake' },248 },249 };250 let [value, found] = denormalize(251 { results: ['1', '2'] },252 catSchema,253 entities,254 );255 expect(value).toMatchSnapshot();256 expect(found).toBe(true);257 [value, found] = denormalize(258 { results: ['1', '2'] },259 catSchema,260 fromJS(entities),261 );262 expect(value).toMatchSnapshot();263 expect(found).toBe(true);264 });265 test('denormalizes should not be found when result array is undefined', () => {266 class Cat extends IDEntity {}267 const catSchema = { results: [Cat] };268 const entities = {269 Cat: {270 '1': { id: '1', name: 'Milo' },271 '2': { id: '2', name: 'Jake' },272 },273 };274 let [value, found] = denormalize(275 { results: undefined },276 catSchema,277 entities,278 );279 expect(value).toMatchSnapshot();280 expect(found).toBe(false);281 [value, found] = denormalize(282 { results: undefined },283 catSchema,284 fromJS(entities),285 );286 expect(value).toMatchSnapshot();287 expect(found).toBe(false);288 });289 test('denormalizes with missing entity should have true second value', () => {290 class Cat extends IDEntity {}291 const entities = {292 Cat: {293 '1': { id: '1', name: 'Milo' },294 '2': { id: '2', name: 'Jake' },295 },296 };297 let [value, foundEntities] = denormalize(298 [{ data: '1' }, { data: '2' }, { data: '3' }],299 [{ data: Cat }],300 entities,301 );302 expect(value).toMatchSnapshot();303 expect(foundEntities).toBe(true);304 [value, foundEntities] = denormalize(305 [{ data: '1' }, { data: '2' }, { data: '3' }],306 [{ data: Cat }],307 fromJS(entities),308 );309 expect(value).toMatchSnapshot();310 expect(foundEntities).toBe(true);311 });312 test('returns the input value if is not an array', () => {313 class Filling extends IDEntity {}314 class Taco extends IDEntity {315 static schema = { fillings: [Filling] };316 }317 const entities = {318 Taco: {319 '123': {320 id: '123',321 fillings: null,322 },323 },324 };325 expect(denormalize('123', Taco, entities)).toMatchSnapshot();326 expect(denormalize('123', Taco, fromJS(entities))).toMatchSnapshot();327 });328 });329 describe('Class', () => {330 test('denormalizes a single entity', () => {331 class Cat extends IDEntity {}332 const entities = {333 Cat: {334 '1': { id: '1', name: 'Milo' },335 '2': { id: '2', name: 'Jake' },336 },337 };338 const catList = new schema.Array(Cat);339 expect(denormalize(['1', '2'], catList, entities)).toMatchSnapshot();340 expect(341 denormalize(['1', '2'], catList, fromJS(entities)),342 ).toMatchSnapshot();343 });344 test('denormalizes plain arrays with nothing inside', () => {345 class User extends IDEntity {}346 const entities = {347 User: {348 '1': { id: '1', name: 'Jane' },349 },350 };351 expect(352 denormalize(353 { user: '1' },354 { user: User, tacos: new schema.Array() },355 entities,356 ),357 ).toMatchSnapshot();358 expect(359 denormalize(360 { user: '1' },361 { user: User, tacos: new schema.Array() },362 fromJS(entities),363 ),364 ).toMatchSnapshot();365 expect(366 denormalize(367 fromJS({ user: '1' }),368 { user: User, tacos: new schema.Array() },369 fromJS(entities),370 ),371 ).toMatchSnapshot();372 expect(373 denormalize(374 { user: '1', tacos: [] },375 { user: User, tacos: new schema.Array() },376 entities,377 ),378 ).toMatchSnapshot();379 expect(380 denormalize(381 { user: '1', tacos: [] },382 { user: User, tacos: new schema.Array() },383 fromJS(entities),384 ),385 ).toMatchSnapshot();386 expect(387 denormalize(388 fromJS({ user: '1', tacos: [] }),389 { user: User, tacos: new schema.Array() },390 fromJS(entities),391 ),392 ).toMatchSnapshot();393 });394 test('denormalizes plain arrays with plain object inside', () => {395 class User extends IDEntity {}396 const entities = {397 User: {398 '1': { id: '1', name: 'Jane' },399 },400 };401 expect(402 denormalize(403 { user: '1' },404 { user: User, tacos: new schema.Array({ next: '' }) },405 entities,406 ),407 ).toMatchSnapshot();408 expect(409 denormalize(410 { user: '1' },411 { user: User, tacos: new schema.Array({ next: '' }) },412 fromJS(entities),413 ),414 ).toMatchSnapshot();415 expect(416 denormalize(417 fromJS({ user: '1' }),418 { user: User, tacos: new schema.Array({ next: '' }) },419 fromJS(entities),420 ),421 ).toMatchSnapshot();422 expect(423 denormalize(424 { user: '1', tacos: [] },425 { user: User, tacos: new schema.Array({ next: '' }) },426 entities,427 ),428 ).toMatchSnapshot();429 expect(430 denormalize(431 { user: '1', tacos: [] },432 { user: User, tacos: new schema.Array({ next: '' }) },433 fromJS(entities),434 ),435 ).toMatchSnapshot();436 expect(437 denormalize(438 fromJS({ user: '1', tacos: [] }),439 { user: User, tacos: new schema.Array({ next: '' }) },440 fromJS(entities),441 ),442 ).toMatchSnapshot();443 });444 test('denormalizes nested in object', () => {445 class Cat extends IDEntity {}446 const catSchema = { results: new schema.Array(Cat) };447 const entities = {448 Cat: {449 '1': { id: '1', name: 'Milo' },450 '2': { id: '2', name: 'Jake' },451 },452 };453 expect(454 denormalize({ results: ['1', '2'] }, catSchema, entities),455 ).toMatchSnapshot();456 expect(457 denormalize({ results: ['1', '2'] }, catSchema, fromJS(entities)),458 ).toMatchSnapshot();459 });460 test('denormalizes nested in object with primitive', () => {461 class Cat extends IDEntity {}462 const catSchema = { results: new schema.Array(Cat), nextPage: '' };463 const entities = {464 Cat: {465 '1': { id: '1', name: 'Milo' },466 '2': { id: '2', name: 'Jake' },467 },468 };469 let [value, found] = denormalize(470 { results: ['1', '2'] },471 catSchema,472 entities,473 );474 expect(value).toMatchSnapshot();475 expect(found).toBe(true);476 [value, found] = denormalize(477 { results: ['1', '2'] },478 catSchema,479 fromJS(entities),480 );481 expect(value).toMatchSnapshot();482 expect(found).toBe(true);483 });484 test('denormalizes should not be found when result array is undefined', () => {485 class Cat extends IDEntity {}486 const catSchema = { results: new schema.Array(Cat) };487 const entities = {488 Cat: {489 '1': { id: '1', name: 'Milo' },490 '2': { id: '2', name: 'Jake' },491 },492 };493 let [value, found] = denormalize(494 { results: undefined },495 catSchema,496 entities,497 );498 expect(value).toMatchSnapshot();499 expect(found).toBe(false);500 [value, found] = denormalize(501 { results: undefined },502 catSchema,503 fromJS(entities),504 );505 expect(value).toMatchSnapshot();506 expect(found).toBe(false);507 });508 test('denormalizes with missing entity should have true second value', () => {509 class Cat extends IDEntity {}510 const entities = {511 Cat: {512 '1': { id: '1', name: 'Milo' },513 '2': { id: '2', name: 'Jake' },514 },515 };516 const catList = new schema.Array(Cat);517 expect(denormalize(['1', '2', '3'], catList, entities)).toMatchSnapshot();518 expect(519 denormalize(['1', '2', '3'], catList, fromJS(entities)),520 ).toMatchSnapshot();521 });522 test('denormalizes multiple entities', () => {523 class Cat extends IDEntity {}524 class Person extends IDEntity {}525 const listSchema = new schema.Array(526 {527 Cat: Cat,528 dogs: {},529 people: Person,530 },531 (input, parent, key) => input.type || 'dogs',532 );533 const entities = {534 Cat: {535 '123': {536 id: '123',537 type: 'Cat',538 },539 '456': {540 id: '456',541 type: 'Cat',542 },543 },544 Person: {545 '123': {546 id: '123',547 type: 'people',548 },549 },550 };551 const input = [552 { id: '123', schema: 'Cat' },553 { id: '123', schema: 'people' },554 { id: { id: '789' }, schema: 'dogs' },555 { id: '456', schema: 'Cat' },556 ];557 expect(denormalize(input, listSchema, entities)).toMatchSnapshot();558 expect(559 denormalize(input, listSchema, fromJS(entities)),560 ).toMatchSnapshot();561 });562 test('returns the input value if is not an array', () => {563 class Filling extends IDEntity {}564 const fillings = new schema.Array(Filling);565 class Taco extends IDEntity {566 static schema = { fillings };567 }568 const entities = {569 Taco: {570 '123': {571 id: '123',572 fillings: {},573 },574 },575 };576 expect(denormalize('123', Taco, entities)).toMatchSnapshot();577 expect(denormalize('123', Taco, fromJS(entities))).toMatchSnapshot();578 });579 test('does not assume mapping of schema to attribute values when schemaAttribute is not set', () => {580 class Cat extends IDEntity {}581 const catRecord = new schema.Object({582 cat: Cat,583 });584 const catList = new schema.Array(catRecord);585 const input = [586 { cat: { id: '1' }, id: '5' },587 { cat: { id: '2' }, id: '6' },588 ];589 const output = normalize(input, catList);590 expect(output).toMatchSnapshot();591 expect(denormalize(output.result, catList, output.entities)).toEqual([592 input,593 true,594 false,595 ]);596 });597 });...

Full Screen

Full Screen

storeLegacy-v15-test.js

Source:storeLegacy-v15-test.js Github

copy

Full Screen

...29 const Component = () => <div>Hi</div>;30 act(() =>31 ReactDOM.render(<Component count={4} />, document.createElement('div')),32 );33 expect(store).toMatchSnapshot('1: mount');34 expect(store.roots).toHaveLength(1);35 const rootID = store.roots[0];36 expect(() => store.toggleIsCollapsed(rootID, true)).toThrow(37 'Root nodes cannot be collapsed',38 );39 });40 describe('collapseNodesByDefault:false', () => {41 beforeEach(() => {42 store.collapseNodesByDefault = false;43 });44 it('should support mount and update operations', () => {45 const Grandparent = ({count}) => (46 <div>47 <Parent count={count} />48 <Parent count={count} />49 </div>50 );51 const Parent = ({count}) => (52 <div>53 {new Array(count).fill(true).map((_, index) => (54 <Child key={index} />55 ))}56 </div>57 );58 const Child = () => <div>Hi!</div>;59 const container = document.createElement('div');60 act(() => ReactDOM.render(<Grandparent count={4} />, container));61 expect(store).toMatchSnapshot('1: mount');62 act(() => ReactDOM.render(<Grandparent count={2} />, container));63 expect(store).toMatchSnapshot('2: update');64 act(() => ReactDOM.unmountComponentAtNode(container));65 expect(store).toMatchSnapshot('3: unmount');66 });67 it('should support mount and update operations for multiple roots', () => {68 const Parent = ({count}) => (69 <div>70 {new Array(count).fill(true).map((_, index) => (71 <Child key={index} />72 ))}73 </div>74 );75 const Child = () => <div>Hi!</div>;76 const containerA = document.createElement('div');77 const containerB = document.createElement('div');78 act(() => {79 ReactDOM.render(<Parent key="A" count={3} />, containerA);80 ReactDOM.render(<Parent key="B" count={2} />, containerB);81 });82 expect(store).toMatchSnapshot('1: mount');83 act(() => {84 ReactDOM.render(<Parent key="A" count={4} />, containerA);85 ReactDOM.render(<Parent key="B" count={1} />, containerB);86 });87 expect(store).toMatchSnapshot('2: update');88 act(() => ReactDOM.unmountComponentAtNode(containerB));89 expect(store).toMatchSnapshot('3: unmount B');90 act(() => ReactDOM.unmountComponentAtNode(containerA));91 expect(store).toMatchSnapshot('4: unmount A');92 });93 it('should not filter DOM nodes from the store tree', () => {94 const Grandparent = ({flip}) => (95 <div>96 <div>97 <Parent flip={flip} />98 </div>99 <Parent flip={flip} />100 <Nothing />101 </div>102 );103 const Parent = ({flip}) => (104 <div>105 {flip ? 'foo' : null}106 <Child />107 {flip && [null, 'hello', 42]}108 {flip ? 'bar' : 'baz'}109 </div>110 );111 const Child = () => <div>Hi!</div>;112 const Nothing = () => null;113 const container = document.createElement('div');114 act(() =>115 ReactDOM.render(<Grandparent count={4} flip={false} />, container),116 );117 expect(store).toMatchSnapshot('1: mount');118 act(() =>119 ReactDOM.render(<Grandparent count={4} flip={true} />, container),120 );121 expect(store).toMatchSnapshot('2: update');122 act(() => ReactDOM.unmountComponentAtNode(container));123 expect(store).toMatchSnapshot('5: unmount');124 });125 it('should support collapsing parts of the tree', () => {126 const Grandparent = ({count}) => (127 <div>128 <Parent count={count} />129 <Parent count={count} />130 </div>131 );132 const Parent = ({count}) => (133 <div>134 {new Array(count).fill(true).map((_, index) => (135 <Child key={index} />136 ))}137 </div>138 );139 const Child = () => <div>Hi!</div>;140 act(() =>141 ReactDOM.render(142 <Grandparent count={2} />,143 document.createElement('div'),144 ),145 );146 expect(store).toMatchSnapshot('1: mount');147 const grandparentID = store.getElementIDAtIndex(0);148 const parentOneID = store.getElementIDAtIndex(2);149 const parentTwoID = store.getElementIDAtIndex(8);150 act(() => store.toggleIsCollapsed(parentOneID, true));151 expect(store).toMatchSnapshot('2: collapse first Parent');152 act(() => store.toggleIsCollapsed(parentTwoID, true));153 expect(store).toMatchSnapshot('3: collapse second Parent');154 act(() => store.toggleIsCollapsed(parentOneID, false));155 expect(store).toMatchSnapshot('4: expand first Parent');156 act(() => store.toggleIsCollapsed(grandparentID, true));157 expect(store).toMatchSnapshot('5: collapse Grandparent');158 act(() => store.toggleIsCollapsed(grandparentID, false));159 expect(store).toMatchSnapshot('6: expand Grandparent');160 });161 it('should support adding and removing children', () => {162 const Root = ({children}) => <div>{children}</div>;163 const Component = () => <div />;164 const container = document.createElement('div');165 act(() =>166 ReactDOM.render(167 <Root>168 <Component key="a" />169 </Root>,170 container,171 ),172 );173 expect(store).toMatchSnapshot('1: mount');174 act(() =>175 ReactDOM.render(176 <Root>177 <Component key="a" />178 <Component key="b" />179 </Root>,180 container,181 ),182 );183 expect(store).toMatchSnapshot('2: add child');184 act(() =>185 ReactDOM.render(186 <Root>187 <Component key="b" />188 </Root>,189 container,190 ),191 );192 expect(store).toMatchSnapshot('3: remove child');193 });194 it('should support reordering of children', () => {195 const Root = ({children}) => <div>{children}</div>;196 const Component = () => <div />;197 const Foo = () => <div>{[<Component key="0" />]}</div>;198 const Bar = () => (199 <div>{[<Component key="0" />, <Component key="1" />]}</div>200 );201 const foo = <Foo key="foo" />;202 const bar = <Bar key="bar" />;203 const container = document.createElement('div');204 act(() => ReactDOM.render(<Root>{[foo, bar]}</Root>, container));205 expect(store).toMatchSnapshot('1: mount');206 act(() => ReactDOM.render(<Root>{[bar, foo]}</Root>, container));207 expect(store).toMatchSnapshot('2: reorder children');208 act(() => store.toggleIsCollapsed(store.getElementIDAtIndex(0), true));209 expect(store).toMatchSnapshot('3: collapse root');210 act(() => store.toggleIsCollapsed(store.getElementIDAtIndex(0), false));211 expect(store).toMatchSnapshot('4: expand root');212 });213 });214 describe('collapseNodesByDefault:true', () => {215 beforeEach(() => {216 store.collapseNodesByDefault = true;217 });218 it('should support mount and update operations', () => {219 const Parent = ({count}) => (220 <div>221 {new Array(count).fill(true).map((_, index) => (222 <Child key={index} />223 ))}224 </div>225 );226 const Child = () => <div>Hi!</div>;227 const container = document.createElement('div');228 act(() =>229 ReactDOM.render(230 <div>231 <Parent count={1} />232 <Parent count={3} />233 </div>,234 container,235 ),236 );237 expect(store).toMatchSnapshot('1: mount');238 act(() =>239 ReactDOM.render(240 <div>241 <Parent count={2} />242 <Parent count={1} />243 </div>,244 container,245 ),246 );247 expect(store).toMatchSnapshot('2: update');248 act(() => ReactDOM.unmountComponentAtNode(container));249 expect(store).toMatchSnapshot('3: unmount');250 });251 it('should support mount and update operations for multiple roots', () => {252 const Parent = ({count}) => (253 <div>254 {new Array(count).fill(true).map((_, index) => (255 <Child key={index} />256 ))}257 </div>258 );259 const Child = () => <div>Hi!</div>;260 const containerA = document.createElement('div');261 const containerB = document.createElement('div');262 act(() => {263 ReactDOM.render(<Parent key="A" count={3} />, containerA);264 ReactDOM.render(<Parent key="B" count={2} />, containerB);265 });266 expect(store).toMatchSnapshot('1: mount');267 act(() => {268 ReactDOM.render(<Parent key="A" count={4} />, containerA);269 ReactDOM.render(<Parent key="B" count={1} />, containerB);270 });271 expect(store).toMatchSnapshot('2: update');272 act(() => ReactDOM.unmountComponentAtNode(containerB));273 expect(store).toMatchSnapshot('3: unmount B');274 act(() => ReactDOM.unmountComponentAtNode(containerA));275 expect(store).toMatchSnapshot('4: unmount A');276 });277 it('should not filter DOM nodes from the store tree', () => {278 const Grandparent = ({flip}) => (279 <div>280 <div>281 <Parent flip={flip} />282 </div>283 <Parent flip={flip} />284 <Nothing />285 </div>286 );287 const Parent = ({flip}) => (288 <div>289 {flip ? 'foo' : null}290 <Child />291 {flip && [null, 'hello', 42]}292 {flip ? 'bar' : 'baz'}293 </div>294 );295 const Child = () => <div>Hi!</div>;296 const Nothing = () => null;297 const container = document.createElement('div');298 act(() =>299 ReactDOM.render(<Grandparent count={4} flip={false} />, container),300 );301 expect(store).toMatchSnapshot('1: mount');302 act(() => store.toggleIsCollapsed(store.getElementIDAtIndex(0), false));303 expect(store).toMatchSnapshot('2: expand Grandparent');304 act(() => store.toggleIsCollapsed(store.getElementIDAtIndex(1), false));305 expect(store).toMatchSnapshot('3: expand div');306 act(() =>307 ReactDOM.render(<Grandparent count={4} flip={true} />, container),308 );309 expect(store).toMatchSnapshot('4: final update');310 act(() => ReactDOM.unmountComponentAtNode(container));311 expect(store).toMatchSnapshot('5: unmount');312 });313 it('should support expanding parts of the tree', () => {314 const Grandparent = ({count}) => (315 <div>316 <Parent count={count} />317 <Parent count={count} />318 </div>319 );320 const Parent = ({count}) => (321 <div>322 {new Array(count).fill(true).map((_, index) => (323 <Child key={index} />324 ))}325 </div>326 );327 const Child = () => <div>Hi!</div>;328 act(() =>329 ReactDOM.render(330 <Grandparent count={2} />,331 document.createElement('div'),332 ),333 );334 expect(store).toMatchSnapshot('1: mount');335 const grandparentID = store.getElementIDAtIndex(0);336 act(() => store.toggleIsCollapsed(grandparentID, false));337 expect(store).toMatchSnapshot('2: expand Grandparent');338 const parentDivID = store.getElementIDAtIndex(1);339 act(() => store.toggleIsCollapsed(parentDivID, false));340 expect(store).toMatchSnapshot('3: expand parent div');341 const parentOneID = store.getElementIDAtIndex(2);342 const parentTwoID = store.getElementIDAtIndex(3);343 act(() => store.toggleIsCollapsed(parentOneID, false));344 expect(store).toMatchSnapshot('4: expand first Parent');345 act(() => store.toggleIsCollapsed(parentTwoID, false));346 expect(store).toMatchSnapshot('5: expand second Parent');347 act(() => store.toggleIsCollapsed(parentOneID, true));348 expect(store).toMatchSnapshot('6: collapse first Parent');349 act(() => store.toggleIsCollapsed(parentTwoID, true));350 expect(store).toMatchSnapshot('7: collapse second Parent');351 act(() => store.toggleIsCollapsed(grandparentID, true));352 expect(store).toMatchSnapshot('8: collapse Grandparent');353 });354 it('should support expanding deep parts of the tree', () => {355 const Wrapper = ({forwardedRef}) => (356 <Nested depth={3} forwardedRef={forwardedRef} />357 );358 const Nested = ({depth, forwardedRef}) =>359 depth > 0 ? (360 <Nested depth={depth - 1} forwardedRef={forwardedRef} />361 ) : (362 <div ref={forwardedRef} />363 );364 let ref = null;365 const refSetter = value => {366 ref = value;367 };368 act(() =>369 ReactDOM.render(370 <Wrapper forwardedRef={refSetter} />,371 document.createElement('div'),372 ),373 );374 expect(store).toMatchSnapshot('1: mount');375 const deepestedNodeID = global.agent.getIDForNode(ref);376 act(() => store.toggleIsCollapsed(deepestedNodeID, false));377 expect(store).toMatchSnapshot('2: expand deepest node');378 const rootID = store.getElementIDAtIndex(0);379 act(() => store.toggleIsCollapsed(rootID, true));380 expect(store).toMatchSnapshot('3: collapse root');381 act(() => store.toggleIsCollapsed(rootID, false));382 expect(store).toMatchSnapshot('4: expand root');383 const id = store.getElementIDAtIndex(1);384 act(() => store.toggleIsCollapsed(id, true));385 expect(store).toMatchSnapshot('5: collapse middle node');386 act(() => store.toggleIsCollapsed(id, false));387 expect(store).toMatchSnapshot('6: expand middle node');388 });389 it('should support reordering of children', () => {390 const Root = ({children}) => <div>{children}</div>;391 const Component = () => <div />;392 const Foo = () => <div>{[<Component key="0" />]}</div>;393 const Bar = () => (394 <div>{[<Component key="0" />, <Component key="1" />]}</div>395 );396 const foo = <Foo key="foo" />;397 const bar = <Bar key="bar" />;398 const container = document.createElement('div');399 act(() => ReactDOM.render(<Root>{[foo, bar]}</Root>, container));400 expect(store).toMatchSnapshot('1: mount');401 act(() => ReactDOM.render(<Root>{[bar, foo]}</Root>, container));402 expect(store).toMatchSnapshot('2: reorder children');403 act(() => store.toggleIsCollapsed(store.getElementIDAtIndex(0), false));404 expect(store).toMatchSnapshot('3: expand root');405 act(() => store.toggleIsCollapsed(store.getElementIDAtIndex(1), false));406 expect(store).toMatchSnapshot('4: expand div');407 act(() => {408 store.toggleIsCollapsed(store.getElementIDAtIndex(3), false);409 store.toggleIsCollapsed(store.getElementIDAtIndex(2), false);410 });411 expect(store).toMatchSnapshot('4: expand leaves');412 act(() => store.toggleIsCollapsed(store.getElementIDAtIndex(0), true));413 expect(store).toMatchSnapshot('5: collapse root');414 });415 });...

Full Screen

Full Screen

Props.spec.js

Source:Props.spec.js Github

copy

Full Screen

...56 <PropsRenderer57 props={[{ type: { name: 'string' }, required: false, description: '', name: 'color' }]}58 />59 );60 expect(actual).toMatchSnapshot();61 });62});63describe('props columns', () => {64 it('should render PropTypes.string', () => {65 const actual = render(['color: PropTypes.string']);66 expect(actual).toMatchSnapshot();67 });68 it('should render PropTypes.string with a default value', () => {69 const actual = render(['color: PropTypes.string'], ['color: "pink"']);70 expect(actual).toMatchSnapshot();71 });72 it('should render PropTypes.string.isRequired', () => {73 const actual = render(['color: PropTypes.string.isRequired']);74 expect(actual).toMatchSnapshot();75 });76 it('should render PropTypes.arrayOf', () => {77 const actual = render(['colors: PropTypes.arrayOf(PropTypes.string)']);78 expect(actual).toMatchSnapshot();79 });80 it('should render PropTypes.arrayOf(PropTypes.shape)', () => {81 const actual = render([82 'foos: PropTypes.arrayOf(PropTypes.shape({bar: PropTypes.number, baz: PropTypes.any}))',83 ]);84 expect(actual).toMatchSnapshot();85 });86 it('should render PropTypes.instanceOf', () => {87 const actual = render(['num: PropTypes.instanceOf(Number)']);88 expect(actual).toMatchSnapshot();89 });90 it('should render PropTypes.shape', () => {91 const actual = render([92 'foo: PropTypes.shape({bar: PropTypes.number.isRequired, baz: PropTypes.any})',93 ]);94 expect(actual).toMatchSnapshot();95 });96 it('should render PropTypes.shape with formatted defaultProps', () => {97 const actual = render(98 [99 `100 foo: PropTypes.shape({101 bar: PropTypes.number.isRequired,102 baz: PropTypes.any,103 })104 `,105 ],106 [107 `108 foo: {109 bar: 123, baz() {110 return 'foo';111 },112 bing() {113 return 'badaboom';114 },115 trotskij: () => 1935,116 qwarc: { si: 'señor', },117 }118 `,119 ]120 );121 expect(actual).toMatchSnapshot();122 });123 it('should render PropTypes.shape defaultProps, falling back to Object', () => {124 const actual = render(125 [126 `127 foo: PropTypes.shape({128 bar: PropTypes.number.isRequired,129 baz: PropTypes.any,130 })131 `,132 ],133 [134 `135 foo: somethingThatDoesntExist136 `,137 ]138 );139 expect(actual).toMatchSnapshot();140 });141 it('should render PropTypes.shape with description', () => {142 const actual = render([143 `foo: PropTypes.shape({144 /**145 * Number146 */147 bar: PropTypes.number.isRequired,148 /** Any */149 baz: PropTypes.any150 })`,151 ]);152 expect(actual).toMatchSnapshot();153 });154 it('should render PropTypes.objectOf', () => {155 const actual = render(['colors: PropTypes.objectOf(PropTypes.string)']);156 expect(actual).toMatchSnapshot();157 });158 it('should render PropTypes.objectOf(PropTypes.shape)', () => {159 const actual = render([160 `colors: PropTypes.objectOf(161 PropTypes.shape({162 bar: PropTypes.number.isRequired,163 baz: PropTypes.any164 })165 )`,166 ]);167 expect(actual).toMatchSnapshot();168 });169 it('should render PropTypes.oneOf', () => {170 const actual = render(['size: PropTypes.oneOf(["small", "normal", "large"])']);171 expect(actual).toMatchSnapshot();172 });173 it('should render PropTypes.oneOfType', () => {174 const actual = render(['union: PropTypes.oneOfType([PropTypes.string, PropTypes.number])']);175 expect(actual).toMatchSnapshot();176 });177 it('should render description in Markdown', () => {178 const actual = render(['/**\n * Label\n */\ncolor: PropTypes.string']);179 expect(actual).toMatchSnapshot();180 });181 it('should render unknown proptype for a prop when a relevant proptype is not assigned', () => {182 const actual = render([], ['color: "pink"']);183 expect(actual).toMatchSnapshot();184 });185 it('should render function body in tooltip', () => {186 const actual = render(['fn: PropTypes.func'], ['fn: (e) => console.log(e)']);187 expect(actual).toMatchSnapshot();188 });189 it('should render function defaultValue as code when undefined', () => {190 const actual = render(['fn: PropTypes.func'], ['fn: undefined']);191 expect(actual).toMatchSnapshot();192 });193 it('should render function defaultValue as code when null', () => {194 const actual = render(['fn: PropTypes.func'], ['fn: null']);195 expect(actual).toMatchSnapshot();196 });197 it('should render arguments from JsDoc tags', () => {198 const props = [199 {200 name: 'size',201 type: {202 name: 'number',203 },204 required: false,205 description: 'Test description',206 tags: {207 arg: [208 {209 name: 'Foo',210 description: 'Converts foo to bar',211 type: { name: 'Array' },212 },213 ],214 param: [215 {216 name: 'Bar',217 },218 ],219 },220 },221 ];222 const actual = shallow(<ColumnsRenderer props={props} />);223 expect(actual).toMatchSnapshot();224 });225 it('should render return from JsDoc tags', () => {226 const getProps = tag => [227 {228 name: 'size',229 type: {230 name: 'number',231 },232 required: false,233 description: 'Test description',234 tags: {235 [tag]: [236 {237 title: 'Foo',238 description: 'Returns foo from bar',239 type: { name: 'Array' },240 },241 ],242 },243 },244 ];245 const actualForReturn = shallow(<ColumnsRenderer props={getProps('return')} />);246 expect(actualForReturn).toMatchSnapshot();247 const actualForReturns = shallow(<ColumnsRenderer props={getProps('returns')} />);248 expect(actualForReturns).toMatchSnapshot();249 });250 it('should render name as deprecated when tag deprecated is present', () => {251 const props = [252 {253 name: 'size',254 type: {255 name: 'number',256 },257 required: false,258 description: 'Test description',259 tags: {260 deprecated: [261 {262 title: 'deprecated',263 description: 'Do not use.',264 },265 ],266 },267 },268 ];269 const actual = shallow(<ColumnsRenderer props={props} />);270 expect(actual).toMatchSnapshot();271 });272 it('should render type string', () => {273 const actual = renderFlow(['foo: string']);274 expect(actual).toMatchSnapshot();275 });276 it('should render optional type string', () => {277 const actual = renderFlow(['foo?: string']);278 expect(actual).toMatchSnapshot();279 });280 it('should render type string with a default value', () => {281 const actual = renderFlow(['foo?: string'], ['foo: "bar"']);282 expect(actual).toMatchSnapshot();283 });284 it('should render literal type', () => {285 const actual = renderFlow(['foo?: "bar"']);286 expect(actual).toMatchSnapshot();287 });288 it('should render object type with body in tooltip', () => {289 const actual = renderFlow(['foo: { bar: string }']);290 expect(actual).toMatchSnapshot();291 });292 it('should render function type with body in tooltip', () => {293 const actual = renderFlow(['foo: () => void']);294 expect(actual).toMatchSnapshot();295 });296 it('should render union type with body in tooltip', () => {297 const actual = renderFlow(['foo: "bar" | number']);298 expect(actual).toMatchSnapshot();299 });300 it('should render tuple type with body in tooltip', () => {301 const actual = renderFlow(['foo: ["bar", number]']);302 expect(actual).toMatchSnapshot();303 });304 it('should render custom class type', () => {305 const actual = renderFlow(['foo: React.ReactNode']);306 expect(actual).toMatchSnapshot();307 });308});309describe('unquote', () => {310 it('should remove double quotes around the string', () => {311 const result = unquote('"foo"');312 expect(result).toBe('foo');313 });314 it('should remove single quotes around the string', () => {315 const result = unquote("'foo'");316 expect(result).toBe('foo');317 });318 it('should not remove quotes in the middle of the string', () => {319 const result = unquote('foo"bar');320 expect(result).toBe('foo"bar');...

Full Screen

Full Screen

md2tex.test.js

Source:md2tex.test.js Github

copy

Full Screen

...13 #### H414 ##### H515 ###### H616 `)17 ).toMatchSnapshot();18 });19 it("headlines with escaped characters", () => {20 expect(21 convert(dd`22 # escapes23 ## blocks24 ### ~ tilde ~25 ### ^I don't know26 ### \\ backslash \\27 ## & other &28 ### % procent %29 ### $ money $ dollar30 ### # hashtag #31 ### _ underscore _32 ###### ({brackets})33 `)34 ).toMatchSnapshot();35 });36 it("headlines with styles and code", () => {37 expect(38 convert(dd`39 # *italic* _underscore_40 ## \`Code\` headline41 `)42 ).toMatchSnapshot();43 });44 it("inline styles", () => {45 expect(46 convert(dd`47 *italic* normal _italic_48 **bold** normal __bold__49 `)50 ).toMatchSnapshot();51 });52 it("inline styles with escaped charachters", () => {53 expect(54 convert(dd`55 *italic* & _italic \\ backslash_56 **bold** {} __bolder $ money__.57 `)58 ).toMatchSnapshot();59 });60 it("inline styles with links and images", () => {61 expect(62 convert(dd`63 *italic* [link](without_any_italic_styles) _italic_64 **bold** ![images](shouldn**t**be__bold__eighter).65 `)66 ).toMatchSnapshot();67 });68 it("inline code blocks", () => {69 expect(70 convert(dd`hi \`code\` and more \`code\` inline`)71 ).toMatchSnapshot();72 });73 it("biblatex source", () => {74 expect(convert(dd`some [source](\`BibRefName\`)`)).toMatchSnapshot();75 });76 it("footnotes", () => {77 expect(convert(dd`some [footnote](footnote text)`)).toMatchSnapshot();78 });79 it("footnotes with inline code", () => {80 expect(convert(dd`some [footnote](footnote \`code\` and more)`)).toMatchSnapshot();81 });82 it("escape special chars in footnotes", () => {83 expect(84 convert(dd`85 I have [the special char # in my footnote](https://vuejs.org/v2/guide/components-slots.html#Scoped-Slots)86 `)87 ).toMatchSnapshot();88 });89 it("images", () => {90 expect(convert(dd`some ![image](url)`)).toMatchSnapshot();91 });92 it("ordered list", () => {93 expect(94 convert(dd`95 1. first entry96 1. first indentation97 1. even more indentation98 2. second entry99 1. indented100 1. and done101 `)102 ).toMatchSnapshot();103 });104 it("unordered list", () => {105 expect(106 convert(dd`107 - first entry108 - first indentation109 - even more indentation110 - second entry111 - indented112 - and done113 `)114 ).toMatchSnapshot();115 });116 it("mixed list", () => {117 expect(118 convert(dd`119 1. first entry120 - first indentation121 - even more indentation122 - second subentry123 2. second entry124 1. indented125 - unorderd sublist126 `)127 ).toMatchSnapshot();128 });129 it("escape chars in lists", () => {130 expect(131 convert(dd`132 - first & second133 - backslash: \\134 `)135 ).toMatchSnapshot();136 });137 it("code blocks", () => {138 expect(139 convert(dd`140 some text before141 \`\`\`js142 console.log("Hi");143 \`\`\`144 and some behind145 `)146 ).toMatchSnapshot();147 });148 it("code block with captions", () => {149 expect(150 convert(dd`151 some text before152 \`\`\`js [JS Hello World]153 console.log("Hi");154 \`\`\`155 `)156 ).toMatchSnapshot();157 });158 it("raw latex blocks", () => {159 expect(160 convert(dd`161 some text before162 \`\`\`latex163 \\textbackslash backslash164 \`\`\`165 and some behind166 `)167 ).toMatchSnapshot();168 });169 it("log error for unsupported heading levels", () => {170 expect(171 convert(dd`172 ######## H8 is unsupported, errors are expected173 `)174 ).toMatchSnapshot();175 });176 it("apply linebreaks", () => {177 expect(178 convert(dd`179 I wan't to be in the same textblock180 but I also wan't to be on a seperate line181 Please, let me go into a new textblock :help:182 `)183 ).toMatchSnapshot();184 });185 it("no linebreak after listings", () => {186 expect(187 convert(dd`188 - I am189 - a List190 With some text directly afterwards191 - I am192 - a List193 With an empty line and text following194 - I am195 - a List196 With an empty line and text following197 with multiple lines should have a linebreak198 `)199 ).toMatchSnapshot();200 });201 it("links directly after links", () => {202 expect(203 convert(dd`204 [link1](target1)[link2](target2)[](target3)205 `)206 ).toMatchSnapshot();207 });...

Full Screen

Full Screen

validation.test.js

Source:validation.test.js Github

copy

Full Screen

1import { isRequired, maxLength, maxValue, minLength, minValue, mustBeEmail, mustBeNumber } from '../validator';2describe('check custom validators', () => {3 beforeAll(() => require('../../../../i18n'));4 it('should validate isRequired', () => {5 expect(isRequired(false)()).toMatchSnapshot();6 expect(isRequired(false)('')).toMatchSnapshot();7 expect(isRequired(false)('test')).toMatchSnapshot();8 expect(isRequired(true)('test')).toMatchSnapshot();9 expect(isRequired()('test')).toMatchSnapshot();10 expect(isRequired()(true)).toMatchSnapshot();11 // incorrect12 expect(isRequired(true)()).toMatchSnapshot();13 expect(isRequired(true)('')).toMatchSnapshot();14 expect(isRequired()()).toMatchSnapshot();15 expect(isRequired()('')).toMatchSnapshot();16 expect(isRequired()(null)).toMatchSnapshot();17 expect(isRequired()(undefined)).toMatchSnapshot();18 expect(isRequired()(0)).toMatchSnapshot();19 expect(isRequired()(false)).toMatchSnapshot();20 });21 it('should validate mustBeNumber', () => {22 expect(mustBeNumber(1)).toMatchSnapshot();23 expect(mustBeNumber('NaN')).toMatchSnapshot();24 });25 it('should validate minValue', () => {26 expect(minValue(10)(10)).toMatchSnapshot();27 expect(minValue(10)(1)).toMatchSnapshot();28 expect(minValue(10)()).toMatchSnapshot();29 });30 it('should validate maxValue', () => {31 expect(maxValue(10)(10)).toMatchSnapshot();32 expect(maxValue(10)(100)).toMatchSnapshot();33 expect(maxValue(10)()).toMatchSnapshot();34 });35 it('should validate minLength', () => {36 expect(minLength(10)('ten chars!')).toMatchSnapshot();37 expect(minLength(10)('less 10')).toMatchSnapshot();38 expect(minLength(10)()).toMatchSnapshot();39 });40 it('should validate maxLength', () => {41 expect(maxLength(10)('ten chars!')).toMatchSnapshot();42 expect(maxLength(10)('over ten chars!')).toMatchSnapshot();43 expect(maxLength(10)()).toMatchSnapshot();44 });45 it('should validate mustBeEmail', () => {46 expect(mustBeEmail('a@a.a')).toMatchSnapshot();47 expect(mustBeEmail('aa.a')).toMatchSnapshot();48 expect(mustBeEmail()).toMatchSnapshot();49 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { toMatchDiffSnapshot } = require('differencify');2expect.extend({ toMatchDiffSnapshot });3const { toMatchImageSnapshot } = require('jest-image-snapshot');4expect.extend({ toMatchImageSnapshot });5const { toMatchImageSnapshot } = require('jest-image-snapshot');6expect.extend({ toMatchImageSnapshot });7const { toMatchImageSnapshot } = require('jest-image-snapshot');8expect.extend({ toMatchImageSnapshot });9const { toMatchImageSnapshot } = require('jest-image-snapshot');10expect.extend({ toMatchImageSnapshot });11const { toMatchImageSnapshot } = require('jest-image-snapshot');12expect.extend({ toMatchImageSnapshot });13const { toMatchImageSnapshot } = require('jest-image-snapshot');14expect.extend({ toMatchImageSnapshot });15const { toMatchImageSnapshot } = require('jest-image-snapshot');16expect.extend({ toMatchImageSnapshot });17const { toMatchImageSnapshot } = require('jest-image-snapshot');18expect.extend({ toMatchImageSnapshot });19const { toMatchImageSnapshot } = require('jest-image-snapshot');20expect.extend({ toMatchImageSnapshot });21const { toMatchImageSnapshot } = require('jest-image-snapshot');22expect.extend({ toMatchImageSnapshot });23const { toMatchImageSnapshot } = require('jest-image-snapshot');24expect.extend({ toMatchImageSnapshot });25const { toMatchImageSnapshot } = require('jest-image-snapshot');26expect.extend({ toMatchImageSnapshot });27const { toMatch

Full Screen

Using AI Code Generation

copy

Full Screen

1import { toMatchDiffSnapshot } from "snapshot-diff";2expect.extend({ toMatchDiffSnapshot });3import { toMatchSnapshot } from "jest-snapshot";4expect.extend({ toMatchSnapshot });5import { toMatchImageSnapshot } from "jest-image-snapshot";6expect.extend({ toMatchImageSnapshot });7import { toMatchImageSnapshot } from "jest-image-snapshot";8expect.extend({ toMatchImageSnapshot });9import { toMatchImageSnapshot } from "jest-image-snapshot";10expect.extend({ toMatchImageSnapshot });11import { toMatchImageSnapshot } from "jest-image-snapshot";12expect.extend({ toMatchImageSnapshot });13import { toMatchImageSnapshot } from "jest-image-snapshot";14expect.extend({ toMatchImageSnapshot });15import { toMatchImageSnapshot } from "jest-image-snapshot";16expect.extend({ toMatchImageSnapshot });17import { toMatchImageSnapshot } from "jest-image-snapshot";18expect.extend({ toMatchImageSnapshot });19import { toMatchImageSnapshot } from "jest-image-snapshot";20expect.extend({ toMatchImageSnapshot });21import { toMatchImageSnapshot } from "jest-image-snapshot";22expect.extend({ toMatchImageSnapshot });23import { toMatchImageSnapshot } from "jest-image-snapshot";24expect.extend({ toMatchImageSnapshot });25import { toMatchImageSnapshot } from "jest-image-snapshot";26expect.extend({ toMatchImageSnapshot });27import { toMatchImageSnapshot } from "jest-image-snapshot";28expect.extend({ toMatchImageSnapshot });

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require("differencify");2const { toMatchImageSnapshot } = require("jest-image-snapshot");3expect.extend({ toMatchImageSnapshot });4describe("test", () => {5 it("test", async () => {6 const differencifyInstance = differencify.init({7 });8 const { page } = await differencifyInstance.launch();9 const image = await page.screenshot();10 expect(image).toMatchImageSnapshot();11 });12});13{14 "dependencies": {15 },16 "devDependencies": {17 },18 "scripts": {19 },20}

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify')2const { toMatchImageSnapshot } = require('jest-image-snapshot')3expect.extend({ toMatchImageSnapshot })4describe('test', () => {5 it('should work', async () => {6 const differencifyInstance = await differencify.init()7 const page = await differencifyInstance.newPage()8 await page.waitForSelector('input[name=q]')9 await page.type('input[name=q]', 'differencify')10 await page.click('input[name=btnK]')11 await page.waitForSelector('div#search')12 const image = await page.screenshot()13 expect(image).toMatchImageSnapshot()14 })15})16differencify.init(options)17Default: {}

Full Screen

Using AI Code Generation

copy

Full Screen

1const toMatchDiffSnapshot = require('snapshot-diff').toMatchDiffSnapshot;2expect.extend({ toMatchDiffSnapshot });3const a = { foo: 'bar', baz: 42 };4const b = { foo: 'bar', baz: 42 };5expect(a).toMatchDiffSnapshot(b);6const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;7expect.extend({ toMatchImageSnapshot });8expect(a).toMatchImageSnapshot(b);9const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;10expect.extend({ toMatchImageSnapshot });11expect(a).toMatchImageSnapshot(b);12const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;13expect.extend({ toMatchImageSnapshot });14expect(a).toMatchImageSnapshot(b);15const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;16expect.extend({ toMatchImageSnapshot });17expect(a).toMatchImageSnapshot(b);18const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;19expect.extend({ toMatchImageSnapshot });20expect(a).toMatchImageSnapshot(b);21const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;22expect.extend({ toMatchImageSnapshot });23expect(a).toMatchImageSnapshot(b);24const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;25expect.extend({ toMatchImageSnapshot });26expect(a).toMatchImageSnapshot(b);27const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;28expect.extend({ toMatchImageSnapshot });29expect(a).toMatchImageSnapshot(b);30const toMatchImageSnapshot = require('snapshot-diff').toMatchImageSnapshot;31expect.extend({ toMatchImageSnapshot });32expect(a).toMatchImageSnapshot(b);33const toMatchImageSnapshot = require('snapshot-d

Full Screen

Using AI Code Generation

copy

Full Screen

1const differencify = require('differencify').default2const differencifyInstance = differencify({ 3})4test('should match snapshot', async () => {5 const page = await browser.newPage()6 const image = await page.screenshot()7 await differencifyInstance.toMatchSnapshot(image, 'google')8 await page.close()9})10const { toMatchImageSnapshot } = require('jest-image-snapshot')11expect.extend({ toMatchImageSnapshot })12test('should match snapshot', async () => {13 const page = await browser.newPage()14 const image = await page.screenshot()15 expect(image).toMatchImageSnapshot()16 await page.close()17})18const { toMatchImageSnapshot } = require('jest-image-snapshot')19expect.extend({ toMatchImageSnapshot })20test('should match snapshot', async () => {21 const page = await browser.newPage()22 const image = await page.screenshot()23 expect(image).toMatchImageSnapshot({24 customDiffConfig: { threshold: 0.01 },25 })26 await page.close()27})28const { toMatchImageSnapshot } = require('jest-image-snapshot')29expect.extend({ toMatchImageSnapshot })30test('should match snapshot', async () => {31 const page = await browser.newPage()32 const image = await page.screenshot()33 expect(image).toMatchImageSnapshot({

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run differencify automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful