Skip to content

Commit

Permalink
[Docs] clean up linting errors in test guides
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jun 17, 2017
1 parent 12cdf2d commit ad97e30
Show file tree
Hide file tree
Showing 8 changed files with 127 additions and 107 deletions.
4 changes: 2 additions & 2 deletions docs/guides/browserify.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ react/lib/ExecutionEnvironment
Here is an example piece of configuration code marking these as external:

```js
var browserify = require('browserify');
const browserify = require('browserify');

var b = browserify();
const b = browserify();

// make sure to mark these as external!
b.external('react/addons');
Expand Down
17 changes: 9 additions & 8 deletions docs/guides/jest.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ You do **not** need to include Jest's own renderer, unless you want to use it _o

If you are using Jest 0.9 – 14.0 with Enzyme and using Jest's automocking feature, you will need to mark react and enzyme to be unmocked in your `package.json`:

```js
/* package.json */

"jest": {
"unmockedModulePathPatterns": [
"node_modules/react/",
"node_modules/enzyme/"
]
`package.json`:
```json
{
"jest": {
"unmockedModulePathPatterns": [
"node_modules/react/",
"node_modules/enzyme/"
]
}
}
```

Expand Down
5 changes: 3 additions & 2 deletions docs/guides/jsdom.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ As a result, a standalone script like the one below is generally a good approach
/* setup.js */

const { JSDOM } = require('jsdom');

const jsdom = new JSDOM('<!doctype html><html><body></body></html>');
const { window } = jsdom;

Expand All @@ -30,7 +31,7 @@ function copyProps(src, target) {
global.window = window;
global.document = window.document;
global.navigator = {
userAgent: 'node.js'
userAgent: 'node.js',
};
copyProps(window, global);
```
Expand All @@ -47,7 +48,7 @@ const jsdom = require('jsdom').jsdom;
global.document = jsdom('');
global.window = document.defaultView;
global.navigator = {
userAgent: 'node.js'
userAgent: 'node.js',
};

function copyProps(src, target) {
Expand Down
79 changes: 44 additions & 35 deletions docs/guides/karma.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,31 @@ See the [webpack guide](webpack.md).

```js
/* karma.conf.js */

webpack: { //kind of a copy of your webpack config
devtool: 'inline-source-map', //just do inline source maps instead of the default
module: {
loaders: [
{
test: /\.js$/,
exclude: /\/node_modules\//,
loader: 'babel',
query: {
presets: ['airbnb']
}
}
]
},
externals: {
'cheerio': 'window',
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true
}
},
module.exports = function karmaConfig(config) {
config.set({
// ...
webpack: { // kind of a copy of your webpack config
devtool: 'inline-source-map', // just do inline source maps instead of the default
module: {
loaders: [{
test: /\.js$/,
exclude: /\/node_modules\//,
loader: 'babel',
query: {
presets: ['airbnb'],
},
}],
},
externals: {
cheerio: 'window',
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
},
},
// ...
});
};
```

## Enzyme + Karma + Browserify
Expand All @@ -43,19 +46,25 @@ See the [browserify guide](browserify.md).

```js
/* karma.conf.js */
browserify: {
debug: true,
transform: [
['babelify', { presets: ['airbnb'] }]
],
configure: function(bundle) {
bundle.on('prebundle', function() {
bundle.external('react/addons');
bundle.external('react/lib/ReactContext');
bundle.external('react/lib/ExecutionEnvironment');
});
}
},
module.exports = function karmaConfig(config) {
config.set({
// ...
browserify: {
debug: true,
transform: [
['babelify', { presets: ['airbnb'] }],
],
configure(bundle) {
bundle.on('prebundle', () => {
bundle.external('react/addons');
bundle.external('react/lib/ReactContext');
bundle.external('react/lib/ExecutionEnvironment');
});
},
},
// ...
});
};
```


Expand Down
12 changes: 7 additions & 5 deletions docs/guides/lab.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,22 @@
# Example Test: Enzyme + Lab + Code

```jsx
const Code = require('code');
const Lab = require('lab');
const lab = exports.lab = Lab.script();
import { shallow, mount, render } from 'enzyme';
import React from 'react';

const Code = require('code');
const Lab = require('lab');

const lab = Lab.script();
exports.lab = lab;

lab.suite('A suite', () => {
lab.test("calls componentDidMount", (done) => {
lab.test('calls componentDidMount', (done) => {
const wrapper = mount(<Foo />);
Code.expect(Foo.prototype.componentDidMount.calledOnce).to.equal(true);
done();
});
});

```


Expand Down
2 changes: 0 additions & 2 deletions docs/guides/mocha.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ import { expect } from 'chai';
import { mount, shallow } from 'enzyme';

describe('<Foo />', () => {

it('calls componentDidMount', () => {
const wrapper = mount(<Foo />);
expect(Foo.prototype.componentDidMount.calledOnce).to.equal(true);
});

});

```
Expand Down
64 changes: 32 additions & 32 deletions docs/guides/tape-ava.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,44 +10,44 @@ npm i --save-dev enzyme
## Tape

```jsx
import test from 'tape'
import React from 'react'
import { shallow, mount } from 'enzyme'

import Foo from '../path/to/foo'

test('shallow', t => {
const wrapper = shallow(<Foo />)
t.equal(wrapper.contains(<span>Foo</span>), true)
})

test('mount', t => {
const wrapper = mount(<Foo />)
const fooInner = wrapper.find('.foo-inner')
t.equal(fooInner.is('.foo-inner'), true)
})
import test from 'tape';
import React from 'react';
import { shallow, mount } from 'enzyme';

import Foo from '../path/to/foo';

test('shallow', (t) => {
const wrapper = shallow(<Foo />);
t.equal(wrapper.contains(<span>Foo</span>), true);
});

test('mount', (t) => {
const wrapper = mount(<Foo />);
const fooInner = wrapper.find('.foo-inner');
t.equal(fooInner.is('.foo-inner'), true);
});
```

## AVA


```jsx
import test from 'ava'
import React from 'react'
import { shallow, mount } from 'enzyme'

import Foo from '../path/to/foo'

test('shallow', t => {
const wrapper = shallow(<Foo />)
t.is(wrapper.contains(<span>Foo</span>), true)
})

test('mount', t => {
const wrapper = mount(<Foo />)
const fooInner = wrapper.find('.foo-inner')
t.is(fooInner.is('.foo-inner'), true)
})
import test from 'ava';
import React from 'react';
import { shallow, mount } from 'enzyme';

import Foo from '../path/to/foo';

test('shallow', (t) => {
const wrapper = shallow(<Foo />);
t.is(wrapper.contains(<span>Foo</span>), true);
});

test('mount', (t) => {
const wrapper = mount(<Foo />);
const fooInner = wrapper.find('.foo-inner');
t.is(fooInner.is('.foo-inner'), true);
});
```

## Example Projects
Expand Down
51 changes: 30 additions & 21 deletions docs/guides/webpack.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,25 +26,32 @@ Depending on if you are using Webpack 1 or Webpack 2 you will need different con

```js
/* webpack.config.js */
// ...
externals: {
'cheerio': 'window',
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true
}
// ...
module.exports = {
// ...
externals: {
cheerio: 'window',
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
},
// ...
};
```

### Webpack 2

```js
externals: {
'cheerio': 'window',
'react/addons': 'react',
'react/lib/ExecutionEnvironment': 'react',
'react/lib/ReactContext': 'react',
},
/* webpack.config.js */
module.exports = {
// ...
externals: {
cheerio: 'window',
'react/addons': 'react',
'react/lib/ExecutionEnvironment': 'react',
'react/lib/ReactContext': 'react',
},
// ...
};
```


Expand All @@ -66,13 +73,15 @@ If you are using React 15, your config should include these externals:

```js
/* webpack.config.js */
// ...
externals: {
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true
}
// ...
module.exports = {
// ...
externals: {
'react/addons': true,
'react/lib/ExecutionEnvironment': true,
'react/lib/ReactContext': true,
},
// ...
};
```

## Example Projects
Expand Down

0 comments on commit ad97e30

Please sign in to comment.