From b2b5f82486306fb291cda17e012984ee8d53f130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Mon, 5 Nov 2018 08:23:22 +0100 Subject: [PATCH] Shallow render linkify test --- client/package.json | 1 + client/src/js/utils/__tests__/util.test.js | 16 ++++++++++------ client/yarn.lock | 15 +++++++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/client/package.json b/client/package.json index 90b5ae8a..bed10d61 100644 --- a/client/package.json +++ b/client/package.json @@ -47,6 +47,7 @@ "postcss-loader": "^3.0.0", "postcss-preset-env": "^6.3.0", "prettier": "1.14.3", + "react-test-renderer": "^16.7.0-alpha.0", "style-loader": "^0.23.1", "terser-webpack-plugin": "^1.1.0", "through2": "^2.0.3", diff --git a/client/src/js/utils/__tests__/util.test.js b/client/src/js/utils/__tests__/util.test.js index ed2322e8..b59dab05 100644 --- a/client/src/js/utils/__tests__/util.test.js +++ b/client/src/js/utils/__tests__/util.test.js @@ -1,7 +1,10 @@ import React from 'react'; +import TestRenderer from 'react-test-renderer'; import { isChannel, isValidNick, isValidChannel, isValidUsername } from '..'; import linkify from '../linkify'; +const render = el => TestRenderer.create(el).toJSON(); + describe('isChannel()', () => { it('it handles strings', () => { expect(isChannel('#cake')).toBe(true); @@ -78,11 +81,12 @@ describe('isValidUsername()', () => { describe('linkify()', () => { const proto = href => (href.indexOf('http') !== 0 ? `http://${href}` : href); - const linkTo = href => ( - - {href} - - ); + const linkTo = href => + render( + + {href} + + ); it('returns the arg when no matches are found', () => [null, undefined, 10, false, true, 'just some text', ''].forEach(input => @@ -111,6 +115,6 @@ describe('linkify()', () => { 'google.com ': [linkTo('google.com'), ' '], '/google.com?': ['/', linkTo('google.com'), '?'] }).forEach(([input, expected]) => - expect(linkify(input)).toEqual(expected) + expect(render(linkify(input))).toEqual(expected) )); }); diff --git a/client/yarn.lock b/client/yarn.lock index 1951d5c9..896c76c5 100644 --- a/client/yarn.lock +++ b/client/yarn.lock @@ -8147,6 +8147,11 @@ react-is@^16.3.2, react-is@^16.6.0: resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.6.0.tgz#456645144581a6e99f6816ae2bd24ee94bdd0c01" integrity sha512-q8U7k0Fi7oxF1HvQgyBjPwDXeMplEsArnKt2iYhuIF86+GBbgLHdAmokL3XUFjTd7Q363OSNG55FOGUdONVn1g== +react-is@^16.7.0-alpha.0: + version "16.7.0-alpha.0" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.7.0-alpha.0.tgz#0c92b82ba8e3d938a09697ce459d019f059421ed" + integrity sha512-8jBaW1rcnUoZFJ4wB5W6xgnNfr70pIW6DadourJ6zkgXZVVcACbUkZyfjI/zI84uyopCJQ6VFHY6qGh6wfJ59Q== + react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4: version "3.0.4" resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" @@ -8165,6 +8170,16 @@ react-redux@^5.1.0: react-is "^16.6.0" react-lifecycles-compat "^3.0.0" +react-test-renderer@16.7.0-alpha.0: + version "16.7.0-alpha.0" + resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-16.7.0-alpha.0.tgz#f60e888621537cf8301fc154e8e98e59fb9c7050" + integrity sha512-yOJTaUgy7V/Lpmv61g2oJdwEGUiAVJ21mYlHtUniUC8rW0HVpTVMDAVSEqgjlCYDfTwGh3hNTvoYaODJzkQKMw== + dependencies: + object-assign "^4.1.1" + prop-types "^15.6.2" + react-is "^16.7.0-alpha.0" + scheduler "^0.11.0-alpha.0" + react-virtualized-auto-sizer@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/react-virtualized-auto-sizer/-/react-virtualized-auto-sizer-1.0.2.tgz#a61dd4f756458bbf63bd895a92379f9b70f803bd"