Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.

Commit 0ecefd5

Browse files
authored
Merge pull request #139 from jamesplease/bug-fixies
Add test demonstrating gh-137
2 parents b5f9a4f + abfbc3f commit 0ecefd5

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
### v2.0.3 (2018/3/2)
4+
5+
**Bug Fixes**
6+
7+
* Fixes a bug where the `lazy` prop was not always respected. Anytime that a new request key was generated,
8+
a request would be made.
9+
310
### v2.0.2 (2018/2/21)
411

512
**Bug Fixes**

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-request",
3-
"version": "2.0.2",
3+
"version": "2.0.3",
44
"description": "Declarative HTTP requests with React.",
55
"main": "lib/index.js",
66
"module": "es/index.js",

src/fetch.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export class Fetch extends React.Component {
109109
method: this.props.method.toUpperCase()
110110
});
111111

112-
if (currentRequestKey !== nextRequestKey) {
112+
if (currentRequestKey !== nextRequestKey && !this.isLazy(nextProps)) {
113113
this.fetchData(nextProps);
114114
}
115115
}

test/index.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,4 +1428,21 @@ describe('laziness', () => {
14281428
expect(beforeFetchMock).toHaveBeenCalledTimes(1);
14291429
});
14301430
});
1431+
1432+
test('it should be respected when the props change', () => {
1433+
fetchMock.get('/test/hangs/double-request2', hangingPromise());
1434+
1435+
const afterFetchMock = jest.fn();
1436+
1437+
const wrapper = shallow(
1438+
<Fetch url="/test/hangs" afterFetch={afterFetchMock} lazy />
1439+
);
1440+
1441+
wrapper.setProps({
1442+
url: '/test/hangs/double-request2'
1443+
});
1444+
1445+
expect(fetchMock.calls('/test/hangs').length).toBe(0);
1446+
expect(fetchMock.calls('/test/hangs/double-request2').length).toBe(0);
1447+
});
14311448
});

0 commit comments

Comments
 (0)