b}
279 | highlightStyle={{
280 | backgroundColor: '#ffcc80',
281 | enabled: true
282 | }}
283 | nodeRenderer={nodeRenderer}
284 | text={text}
285 | />);
286 |
287 | expectChai(onMouseOverHighlightedWord).to.have.property('callCount', 0);
288 | expectChai(onTextHighlighted).to.have.property('callCount', 0);
289 | expectChai(nodeRenderer).to.have.property('callCount', 13);
290 |
291 | let tree = component.toJSON();
292 | expect(tree).toMatchSnapshot();
293 | });
294 | });
295 | });
--------------------------------------------------------------------------------
/test/__snapshots__/Highlightable.test.js.snap:
--------------------------------------------------------------------------------
1 | // Jest Snapshot v1, https://goo.gl/fbAQLP
2 |
3 | exports[`Highlightable component testing update should highlight text 1`] = `
4 |
8 |
11 | t
12 |
13 |
16 | e
17 |
18 |
21 | s
22 |
23 |
26 | t
27 |
28 |
31 |
32 |
33 |
36 | t
37 |
38 |
41 | h
42 |
43 |
46 | e
47 |
48 |
51 |
52 |
53 |
56 | t
57 |
58 |
61 | e
62 |
63 |
66 | x
67 |
68 |
71 | t
72 |
73 |
74 | `;
75 |
76 | exports[`Highlightable component testing update should highlight text 2`] = `
77 |
81 |
90 | t
91 |
92 |
101 | e
102 |
103 |
112 | s
113 |
114 |
123 | t
124 |
125 |
134 |
135 |
136 |
145 | t
146 |
147 |
150 | h
151 |
152 |
155 | e
156 |
157 |
160 |
161 |
162 |
165 | t
166 |
167 |
170 | e
171 |
172 |
175 | x
176 |
177 |
180 | t
181 |
182 |
183 | `;
184 |
185 | exports[`Highlightable component with basic props should render the text without highlight 1`] = `
186 |
190 |
193 | t
194 |
195 |
198 | e
199 |
200 |
203 | s
204 |
205 |
208 | t
209 |
210 |
213 |
214 |
215 |
218 | t
219 |
220 |
223 | h
224 |
225 |
228 | e
229 |
230 |
233 |
234 |
235 |
238 | t
239 |
240 |
243 | e
244 |
245 |
248 | x
249 |
250 |
253 | t
254 |
255 |
256 | `;
257 |
258 | exports[`Highlightable component with custom node should render the text wit custom node 1`] = `
259 |
263 |
266 | t
267 |
268 |
271 | e
272 |
273 |
276 | s
277 |
278 |
281 | t
282 |
283 |
286 |
287 |
288 |
291 | t
292 |
293 |
296 | h
297 |
298 |
301 | e
302 |
303 |
306 |
307 |
308 |
311 | t
312 |
313 |
316 | e
317 |
318 |
321 | x
322 |
323 |
326 | t
327 |
328 |
329 | `;
330 |
331 | exports[`Highlightable component with range props should render with highlighted text 1`] = `
332 |
336 |
345 | t
346 |
347 |
356 | e
357 |
358 |
367 | s
368 |
369 |
378 | t
379 |
380 |
389 |
390 |
391 |
400 | t
401 |
402 |
405 | h
406 |
407 |
410 | e
411 |
412 |
415 |
416 |
417 |
420 | t
421 |
422 |
425 | e
426 |
427 |
430 | x
431 |
432 |
435 | t
436 |
437 |
438 | `;
439 |
440 | exports[`Highlightable component with smiley should highlight text and keep the smiley at the end of the highlighted text 1`] = `
441 |
445 |
448 | t
449 |
450 |
453 | e
454 |
455 |
458 | s
459 |
460 |
463 | t
464 |
465 |
468 |
469 |
470 |
473 | t
474 |
475 |
478 | h
479 |
480 |
483 | e
484 |
485 |
488 |
489 |
490 |
493 | t
494 |
495 |
498 | e
499 |
500 |
503 | x
504 |
505 |
508 | t
509 |
510 |
519 |
520 |
521 |
530 | 😘
531 |
532 |
533 | `;
534 |
535 | exports[`Highlightable component with smiley should highlight text and keep the smiley at the end of the text 1`] = `
536 |
540 |
543 | t
544 |
545 |
548 | e
549 |
550 |
553 | s
554 |
555 |
558 | t
559 |
560 |
563 |
564 |
565 |
568 | t
569 |
570 |
573 | h
574 |
575 |
578 | e
579 |
580 |
583 |
584 |
585 |
588 | t
589 |
590 |
593 | e
594 |
595 |
598 | x
599 |
600 |
603 | t
604 |
605 |
608 |
609 |
610 |
613 | 😘
614 |
615 |
616 | `;
617 |
618 | exports[`Highlightable component with smiley should highlight text and keep the smiley in the middle of the highlighted text 1`] = `
619 |
623 |
626 | t
627 |
628 |
631 | e
632 |
633 |
636 | s
637 |
638 |
641 | t
642 |
643 |
646 |
647 |
648 |
651 | t
652 |
653 |
656 | h
657 |
658 |
661 | e
662 |
663 |
666 |
667 |
668 |
671 | t
672 |
673 |
676 | e
677 |
678 |
681 | x
682 |
683 |
686 | t
687 |
688 |
697 |
698 |
699 |
708 | 😘
709 |
710 |
719 |
720 |
721 |
730 | t
731 |
732 |
741 | e
742 |
743 |
746 | s
747 |
748 |
751 | t
752 |
753 |
756 |
757 |
758 |
761 | a
762 |
763 |
766 | g
767 |
768 |
771 | a
772 |
773 |
776 | i
777 |
778 |
781 | n
782 |
783 |
784 | `;
785 |
786 | exports[`Highlightable component with url should render with highlighted url 1`] = `
787 |
835 | `;
836 |
837 | exports[`Highlightable component with url should render with url 1`] = `
838 |
884 | `;
885 |
--------------------------------------------------------------------------------
/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "declaration": true,
4 | "declarationDir": "./types",
5 | "emitDeclarationOnly": true,
6 | "noImplicitAny": true,
7 | "module": "es6",
8 | "target": "es6",
9 | "jsx": "react",
10 | "allowJs": true,
11 | "moduleResolution": "node",
12 | "skipLibCheck": true,
13 | "allowSyntheticDefaultImports": true
14 | },
15 | "include": ["src"]
16 | }
--------------------------------------------------------------------------------
/webpack.config.js:
--------------------------------------------------------------------------------
1 | const webpack = require('webpack');
2 | const TerserPlugin = require("terser-webpack-plugin");
3 | var path = require('path');
4 |
5 | var libraryName = 'Highlightable';
6 |
7 | var plugins = [], outputFile;
8 |
9 | outputFile = libraryName + '.min.js';
10 |
11 | var config = {
12 | entry: __dirname + '/src/index.ts',
13 | devtool: 'source-map',
14 | output: {
15 | path: __dirname + '/lib',
16 | filename: outputFile,
17 | library: libraryName,
18 | libraryTarget: 'umd',
19 | umdNamedDefine: true
20 | },
21 | optimization: {
22 | minimize: true,
23 | minimizer: [new TerserPlugin()],
24 | },
25 | module: {
26 | rules: [
27 | {
28 | test: /(\.tsx|\.ts)$/,
29 | loader: 'babel-loader',
30 | exclude: /(node_modules|bower_components)/
31 | }
32 | ]
33 | },
34 | resolve: {
35 | modules: [
36 | path.resolve('./src'),
37 | path.resolve('./node_modules')
38 | ],
39 | extensions: ['.js', '.tsx', '.ts']
40 | },
41 | plugins: plugins
42 | };
43 |
44 | module.exports = config;
45 |
--------------------------------------------------------------------------------