Skip to content

Commit 3fe0677

Browse files
authored
Merge pull request basarat#564 from henrebotha/hbotha/nested-code
Fix nesting of code blocks under lists
2 parents 32fa7d4 + 803e03b commit 3fe0677

File tree

1 file changed

+77
-77
lines changed

1 file changed

+77
-77
lines changed

docs/testing/jest.md

Lines changed: 77 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -71,25 +71,25 @@ Add `package.json`:
7171

7272
* For a file `foo.ts`:
7373

74-
```js
75-
export const sum
76-
= (...a: number[]) =>
77-
a.reduce((acc, val) => acc + val, 0);
78-
```
74+
```js
75+
export const sum
76+
= (...a: number[]) =>
77+
a.reduce((acc, val) => acc + val, 0);
78+
```
7979

8080
* A simple `foo.test.ts`:
8181

82-
```js
83-
import { sum } from '../foo';
82+
```js
83+
import { sum } from '../foo';
8484
85-
test('basic', () => {
86-
expect(sum()).toBe(0);
87-
});
85+
test('basic', () => {
86+
expect(sum()).toBe(0);
87+
});
8888
89-
test('basic again', () => {
90-
expect(sum(1, 2)).toBe(3);
91-
});
92-
```
89+
test('basic again', () => {
90+
expect(sum(1, 2)).toBe(3);
91+
});
92+
```
9393

9494
Notes:
9595

@@ -119,81 +119,81 @@ Enzyme allows you to test react components with dom support. There are three ste
119119
1. Install enzyme, types for enzyme, a better snapshot serializer for enzyme, enzyme-adapter-react for your react version `npm i enzyme @types/enzyme enzyme-to-json enzyme-adapter-react-16 -D`
120120
2. Add `"snapshotSerializers"` and `"setupTestFrameworkScriptFile"` to your `jest.config.js`:
121121

122-
```js
123-
module.exports = {
124-
// OTHER PORTIONS AS MENTIONED BEFORE
122+
```js
123+
module.exports = {
124+
// OTHER PORTIONS AS MENTIONED BEFORE
125125

126-
// Setup Enzyme
127-
"snapshotSerializers": ["enzyme-to-json/serializer"],
128-
"setupFilesAfterEnv": ["<rootDir>/src/setupEnzyme.ts"],
129-
}
130-
```
126+
// Setup Enzyme
127+
"snapshotSerializers": ["enzyme-to-json/serializer"],
128+
"setupFilesAfterEnv": ["<rootDir>/src/setupEnzyme.ts"],
129+
}
130+
```
131131

132132
3. Create `src/setupEnzyme.ts` file.
133133

134-
```js
135-
import { configure } from 'enzyme';
136-
import EnzymeAdapter from 'enzyme-adapter-react-16';
137-
configure({ adapter: new EnzymeAdapter() });
138-
```
134+
```js
135+
import { configure } from 'enzyme';
136+
import EnzymeAdapter from 'enzyme-adapter-react-16';
137+
configure({ adapter: new EnzymeAdapter() });
138+
```
139139

140140
Now here is an example react component and test:
141141

142142
* `checkboxWithLabel.tsx`:
143143

144-
```ts
145-
import * as React from 'react';
146-
147-
export class CheckboxWithLabel extends React.Component<{
148-
labelOn: string,
149-
labelOff: string
150-
}, {
151-
isChecked: boolean
152-
}> {
153-
constructor(props) {
154-
super(props);
155-
this.state = { isChecked: false };
156-
}
157-
158-
onChange = () => {
159-
this.setState({ isChecked: !this.state.isChecked });
160-
}
161-
162-
render() {
163-
return (
164-
<label>
165-
<input
166-
type="checkbox"
167-
checked={this.state.isChecked}
168-
onChange={this.onChange}
169-
/>
170-
{this.state.isChecked ? this.props.labelOn : this.props.labelOff}
171-
</label>
172-
);
173-
}
174-
}
175-
176-
```
144+
```ts
145+
import * as React from 'react';
146+
147+
export class CheckboxWithLabel extends React.Component<{
148+
labelOn: string,
149+
labelOff: string
150+
}, {
151+
isChecked: boolean
152+
}> {
153+
constructor(props) {
154+
super(props);
155+
this.state = { isChecked: false };
156+
}
157+
158+
onChange = () => {
159+
this.setState({ isChecked: !this.state.isChecked });
160+
}
161+
162+
render() {
163+
return (
164+
<label>
165+
<input
166+
type="checkbox"
167+
checked={this.state.isChecked}
168+
onChange={this.onChange}
169+
/>
170+
{this.state.isChecked ? this.props.labelOn : this.props.labelOff}
171+
</label>
172+
);
173+
}
174+
}
175+
176+
```
177177

178178
* `checkboxWithLabel.test.tsx`:
179179

180-
```ts
181-
import * as React from 'react';
182-
import { shallow } from 'enzyme';
183-
import { CheckboxWithLabel } from './checkboxWithLabel';
184-
185-
test('CheckboxWithLabel changes the text after click', () => {
186-
const checkbox = shallow(<CheckboxWithLabel labelOn="On" labelOff="Off" />);
187-
188-
// Interaction demo
189-
expect(checkbox.text()).toEqual('Off');
190-
checkbox.find('input').simulate('change');
191-
expect(checkbox.text()).toEqual('On');
192-
193-
// Snapshot demo
194-
expect(checkbox).toMatchSnapshot();
195-
});
196-
```
180+
```ts
181+
import * as React from 'react';
182+
import { shallow } from 'enzyme';
183+
import { CheckboxWithLabel } from './checkboxWithLabel';
184+
185+
test('CheckboxWithLabel changes the text after click', () => {
186+
const checkbox = shallow(<CheckboxWithLabel labelOn="On" labelOff="Off" />);
187+
188+
// Interaction demo
189+
expect(checkbox.text()).toEqual('Off');
190+
checkbox.find('input').simulate('change');
191+
expect(checkbox.text()).toEqual('On');
192+
193+
// Snapshot demo
194+
expect(checkbox).toMatchSnapshot();
195+
});
196+
```
197197

198198
## Reasons why we like jest
199199

0 commit comments

Comments
 (0)