File tree 6 files changed +57
-27
lines changed
6 files changed +57
-27
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "presets" : [" latest " , " react" ],
2
+ "presets" : [" env " , " react" ],
3
3
}
Original file line number Diff line number Diff line change 1
1
{
2
- "parser": "babel-eslint",
3
- "extends": "airbnb",
4
- "env": {
5
- "mocha": true,
6
- "node": true
2
+ "extends": ["eslint:recommended", "plugin:react/recommended"],
3
+ "parserOptions": {
4
+ "ecmaFeatures": {
5
+ "experimentalObjectRestSpread": true,
6
+ "jsx": true
7
+ },
8
+ "sourceType": "module"
7
9
},
8
- "rules ": {
9
- "global-require": 0,
10
- "import/no-extraneous-dependencies": 0 ,
11
- "no-unused-vars ": 1,
12
- "react/jsx-filename-extension ": 0 ,
13
- "react/forbid-prop-types ": 0
10
+ "plugins ": [
11
+ "react"
12
+ ] ,
13
+ "env ": {
14
+ "browser ": true ,
15
+ "mocha ": true
14
16
}
15
17
}
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-typekit" ,
3
- "version" : " 1.0.3 " ,
3
+ "version" : " 1.0.4 " ,
4
4
"description" : " React component that generates Typekit script" ,
5
5
"author" :
" Corey Larson <[email protected] > (http://github.com/coreyleelarson)" ,
6
6
"license" : " MIT" ,
21
21
"clean" : " rimraf lib" ,
22
22
"lint" : " eslint ./src/**" ,
23
23
"prepublish" : " npm run clean && npm run build" ,
24
- "test" : " mocha ./src/**/*.spec.js --compilers js:babel-register"
24
+ "test" : " mocha --require test/setup.js ./src/**/*.spec.js --compilers js:babel-register"
25
25
},
26
26
"devDependencies" : {
27
27
"babel-cli" : " ^6.18.0" ,
28
28
"babel-eslint" : " ^7.1.1" ,
29
- "babel-preset-latest " : " ^6.16.0 " ,
29
+ "babel-preset-env " : " ^1.2.1 " ,
30
30
"babel-preset-react" : " ^6.16.0" ,
31
31
"babel-register" : " ^6.18.0" ,
32
32
"chai" : " ^3.5.0" ,
35
35
"eslint-config-airbnb" : " ^13.0.0" ,
36
36
"eslint-plugin-import" : " ^2.2.0" ,
37
37
"eslint-plugin-jsx-a11y" : " ^2.2.3" ,
38
- "eslint-plugin-react" : " ^6.8.0" ,
38
+ "eslint-plugin-react" : " ^6.10.0" ,
39
+ "jsdom" : " ^9.11.0" ,
40
+ "lodash" : " ^4.17.4" ,
39
41
"mocha" : " ^3.2.0" ,
40
42
"react" : " ^15.4.1" ,
41
43
"react-addons-test-utils" : " ^15.4.1" ,
Original file line number Diff line number Diff line change 1
- /* eslint react/no-danger: 0 */
2
- import React , { PropTypes } from 'react' ;
1
+ import { Component , PropTypes } from 'react' ;
3
2
import buildScript from './utilities/buildScript' ;
4
3
5
- const Typekit = ( { kitId } ) => {
6
- const script = buildScript ( kitId ) ;
7
- return kitId ? ( < script dangerouslySetInnerHTML = { { __html : script } } /> ) : false ;
8
- } ;
4
+ class Typekit extends Component {
5
+ componentDidMount ( ) {
6
+ const is_rendered = document . querySelectorAll ( '.react-typekit' ) . length > 0 ;
7
+ if ( ! is_rendered ) {
8
+ const { kitId } = this . props ;
9
+ const script = document . createElement ( 'script' ) ;
10
+ script . className = 'react-typekit' ;
11
+ script . async = true ;
12
+ script . innerHTML = buildScript ( kitId ) ;
13
+ document . body . appendChild ( script ) ;
14
+ }
15
+ }
16
+
17
+ render ( ) {
18
+ return false ;
19
+ }
20
+ }
9
21
10
22
Typekit . propTypes = {
11
23
kitId : PropTypes . string ,
Original file line number Diff line number Diff line change 1
- /* eslint no-underscore-dangle: 0 */
1
+ import { filter } from 'lodash' ;
2
2
import React from 'react' ;
3
3
import { expect } from 'chai' ;
4
- import { shallow } from 'enzyme' ;
4
+ import { mount } from 'enzyme' ;
5
5
import Typekit from './Typekit' ;
6
6
import buildScript from './utilities/buildScript' ;
7
7
8
8
describe ( '<Typekit />' , ( ) => {
9
9
it ( 'should output typekit script when kitId prop is present' , ( ) => {
10
10
const kitId = 'abc123' ;
11
- const wrapper = shallow ( < Typekit kitId = { kitId } /> ) ;
12
- expect ( wrapper . find ( 'script' ) . node . props . dangerouslySetInnerHTML . __html ) . to . equal ( buildScript ( kitId ) ) ;
11
+ mount ( < Typekit kitId = { kitId } /> ) ;
12
+ const matches = filter ( document . querySelectorAll ( 'script' ) , ( script ) => script . innerHTML === buildScript ( kitId ) ) ;
13
+ expect ( matches ) . to . have . length ( 1 ) ;
13
14
} ) ;
14
15
15
16
it ( 'should output nothing when kitId prop is not present' , ( ) => {
16
- const wrapper = shallow ( < Typekit /> ) ;
17
+ const wrapper = mount ( < Typekit /> ) ;
17
18
expect ( wrapper . html ( ) ) . to . equal ( null ) ;
18
19
} ) ;
19
20
} ) ;
Original file line number Diff line number Diff line change
1
+ import { jsdom } from 'jsdom' ;
2
+
3
+ global . document = jsdom ( '' ) ;
4
+ global . window = document . defaultView ;
5
+ Object . keys ( document . defaultView ) . forEach ( ( property ) => {
6
+ if ( typeof global [ property ] === 'undefined' ) {
7
+ global [ property ] = document . defaultView [ property ] ;
8
+ }
9
+ } ) ;
10
+
11
+ global . navigator = {
12
+ userAgent : 'node.js'
13
+ } ;
You can’t perform that action at this time.
0 commit comments