File tree Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Expand file tree Collapse file tree 3 files changed +10
-8
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ class Ctx {
3
3
this . _temp = '' ;
4
4
this . _parentTemp = `"use strict";return @temp;` ;
5
5
this . _com = null ;
6
- if ( ! ( window . hasOwnProperty ( 'Babel' ) && typeof window . Babel === 'object' ) ) {
6
+ if ( ! ( Object . prototype . hasOwnProperty . call ( window , 'Babel' ) && typeof window . Babel === 'object' ) ) {
7
7
throw new Error ( `string-to-react-component package needs @babel/standalone for working correctly.
8
8
you should load @babel/standalone in the browser.` ) ;
9
9
}
Original file line number Diff line number Diff line change 1
1
import Ctx from './ctx.js' ;
2
- import { TestScheduler } from 'jest' ;
3
2
beforeEach ( ( ) => {
4
3
window . Babel = { } ;
5
4
} ) ;
@@ -53,19 +52,21 @@ describe('methods : ', () => {
53
52
test ( '_validateCodeInsideTheTemp method' , ( ) => {
54
53
expect . assertions ( 3 ) ;
55
54
const ins = new Ctx ( ) ;
56
- try {
55
+ {
57
56
ins . _com = ( ) => { } ;
58
57
ins . _validateCodeInsideTheTemp ( ) ;
59
58
expect ( 1 ) . toBe ( 1 ) ;
60
- } catch ( er ) { }
61
- try {
62
- class c { }
59
+ }
60
+ {
61
+ class c {
62
+ constructor ( ) { }
63
+ }
63
64
ins . _com = c ;
64
65
ins . _validateCodeInsideTheTemp ( ) ;
65
66
expect ( 1 ) . toBe ( 1 ) ;
66
- } catch ( er ) { }
67
+ }
67
68
try {
68
- ins . _com = { } ;
69
+ ins . _com = '' ;
69
70
ins . _validateCodeInsideTheTemp ( ) ;
70
71
} catch ( er ) {
71
72
expect ( er . message ) . toBe ( 'code inside the passed string into string-to-react-component, should be a function' ) ;
Original file line number Diff line number Diff line change
1
+ /* eslint-disable react/prop-types */
1
2
import React , { useRef } from 'react' ;
2
3
window . React = window . React || React ;
3
4
function StringToReactComponent ( { getCtx} , props ) {
You can’t perform that action at this time.
0 commit comments