Shallow render linkify test

This commit is contained in:
Ken-Håvard Lieng 2018-11-05 08:23:22 +01:00
parent 69d5f41270
commit b2b5f82486
3 changed files with 26 additions and 6 deletions

View File

@ -47,6 +47,7 @@
"postcss-loader": "^3.0.0", "postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.3.0", "postcss-preset-env": "^6.3.0",
"prettier": "1.14.3", "prettier": "1.14.3",
"react-test-renderer": "^16.7.0-alpha.0",
"style-loader": "^0.23.1", "style-loader": "^0.23.1",
"terser-webpack-plugin": "^1.1.0", "terser-webpack-plugin": "^1.1.0",
"through2": "^2.0.3", "through2": "^2.0.3",

View File

@ -1,7 +1,10 @@
import React from 'react'; import React from 'react';
import TestRenderer from 'react-test-renderer';
import { isChannel, isValidNick, isValidChannel, isValidUsername } from '..'; import { isChannel, isValidNick, isValidChannel, isValidUsername } from '..';
import linkify from '../linkify'; import linkify from '../linkify';
const render = el => TestRenderer.create(el).toJSON();
describe('isChannel()', () => { describe('isChannel()', () => {
it('it handles strings', () => { it('it handles strings', () => {
expect(isChannel('#cake')).toBe(true); expect(isChannel('#cake')).toBe(true);
@ -78,11 +81,12 @@ describe('isValidUsername()', () => {
describe('linkify()', () => { describe('linkify()', () => {
const proto = href => (href.indexOf('http') !== 0 ? `http://${href}` : href); const proto = href => (href.indexOf('http') !== 0 ? `http://${href}` : href);
const linkTo = href => ( const linkTo = href =>
<a href={proto(href)} rel="noopener noreferrer" target="_blank"> render(
{href} <a href={proto(href)} rel="noopener noreferrer" target="_blank">
</a> {href}
); </a>
);
it('returns the arg when no matches are found', () => it('returns the arg when no matches are found', () =>
[null, undefined, 10, false, true, 'just some text', ''].forEach(input => [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'), ' '],
'/google.com?': ['/', linkTo('google.com'), '?'] '/google.com?': ['/', linkTo('google.com'), '?']
}).forEach(([input, expected]) => }).forEach(([input, expected]) =>
expect(linkify(input)).toEqual(expected) expect(render(linkify(input))).toEqual(expected)
)); ));
}); });

View File

@ -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" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.6.0.tgz#456645144581a6e99f6816ae2bd24ee94bdd0c01"
integrity sha512-q8U7k0Fi7oxF1HvQgyBjPwDXeMplEsArnKt2iYhuIF86+GBbgLHdAmokL3XUFjTd7Q363OSNG55FOGUdONVn1g== 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: react-lifecycles-compat@^3.0.0, react-lifecycles-compat@^3.0.4:
version "3.0.4" version "3.0.4"
resolved "https://registry.yarnpkg.com/react-lifecycles-compat/-/react-lifecycles-compat-3.0.4.tgz#4f1a273afdfc8f3488a8c516bfda78f872352362" 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-is "^16.6.0"
react-lifecycles-compat "^3.0.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: react-virtualized-auto-sizer@^1.0.2:
version "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" resolved "https://registry.yarnpkg.com/react-virtualized-auto-sizer/-/react-virtualized-auto-sizer-1.0.2.tgz#a61dd4f756458bbf63bd895a92379f9b70f803bd"