This repository has been archived by the owner on Jun 16, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixed bug where child_removed was not cleaned up for List
- Loading branch information
1 parent
09e1305
commit 62d48e7
Showing
8 changed files
with
186 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
## 1.1.0 (June 18, 2018) | ||
* added unit test for Value and List | ||
* fixed bug where child_removed was not cleaned up for List | ||
|
||
## 1.0.0 (June 18, 2018) | ||
* added value, list and user | ||
* added umd build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`list should render {} initially 1`] = `"list: {}"`; | ||
|
||
exports[`list when a child is added, component is re-rendered 1`] = `"list: {\\"some key\\":\\"some value\\"}"`; | ||
|
||
exports[`list when a child is changed, component is re-rendered 1`] = `"list: {\\"some key\\":\\"some other value\\"}"`; | ||
|
||
exports[`list when a child is removed, component is re-rendered 1`] = `"list: {}"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
module.exports = () => { | ||
const self = { | ||
onMock: jest.fn((event, listener) => { | ||
return listener | ||
}), | ||
offMock: jest.fn((event, listener) => { | ||
return listener | ||
}), | ||
refMock: jest.fn((path) => { | ||
return { | ||
on: self.onMock, | ||
off: self.offMock | ||
} | ||
}), | ||
Firebase: { | ||
database() { | ||
return { | ||
ref: self.refMock | ||
} | ||
} | ||
} | ||
} | ||
|
||
return self; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
const {createElement} = require('react') | ||
const {create} = require('react-test-renderer') | ||
|
||
const FirebaseMock = require('./firebase-mock') | ||
const ListFactory = require('./list') | ||
|
||
describe('list', () => { | ||
it('should render {} initially', () => { | ||
const {refMock, Firebase} = FirebaseMock() | ||
const List = ListFactory(Firebase) | ||
const component = create(createElement(List, {path: 'some path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[0][0]).toBe('some path') | ||
expect(component.toJSON()) | ||
.toMatchSnapshot() | ||
}) | ||
|
||
it('when a child is added, component is re-rendered', () => { | ||
const {onMock, refMock, Firebase} = FirebaseMock() | ||
const List = ListFactory(Firebase) | ||
const component = create(createElement(List, {path: 'some path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[0][0]).toBe('some path') | ||
expect(onMock.mock.calls[0][0]).toBe('child_added') | ||
const childAddedListener = onMock.mock.calls[0][1] | ||
childAddedListener({ | ||
key: 'some key', | ||
val() { | ||
return 'some value' | ||
} | ||
}) | ||
expect(component.toJSON()) | ||
.toMatchSnapshot() | ||
}) | ||
|
||
it('when a child is removed, component is re-rendered', () => { | ||
const {onMock, refMock, Firebase} = FirebaseMock() | ||
const List = ListFactory(Firebase) | ||
const component = create(createElement(List, {path: 'some path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[0][0]).toBe('some path') | ||
expect(onMock.mock.calls[0][0]).toBe('child_added') | ||
const childAddedListener = onMock.mock.calls[0][1] | ||
childAddedListener({ | ||
key: 'some key', | ||
val() { | ||
return 'some value' | ||
} | ||
}) | ||
expect(onMock.mock.calls[1][0]).toBe('child_removed') | ||
const childRemovedListener = onMock.mock.calls[1][1] | ||
childRemovedListener({ | ||
key: 'some key' | ||
}) | ||
expect(component.toJSON()) | ||
.toMatchSnapshot() | ||
}) | ||
|
||
it('when a child is changed, component is re-rendered', () => { | ||
const {onMock, refMock, Firebase} = FirebaseMock() | ||
const List = ListFactory(Firebase) | ||
const component = create(createElement(List, {path: 'some path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[0][0]).toBe('some path') | ||
expect(onMock.mock.calls[0][0]).toBe('child_added') | ||
const childAddedListener = onMock.mock.calls[0][1] | ||
childAddedListener({ | ||
key: 'some key', | ||
val() { | ||
return 'some value' | ||
} | ||
}) | ||
expect(onMock.mock.calls[2][0]).toBe('child_changed') | ||
const childChangedListener = onMock.mock.calls[2][1] | ||
childChangedListener({ | ||
key: 'some key', | ||
val() { | ||
return 'some other value' | ||
} | ||
}) | ||
expect(component.toJSON()) | ||
.toMatchSnapshot() | ||
}) | ||
|
||
it('when component is unmounted, listeners are removed', () => { | ||
const {onMock, offMock, refMock, Firebase} = FirebaseMock() | ||
const List = ListFactory(Firebase) | ||
const component = create(createElement(List, {path: 'some path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[0][0]).toBe('some path') | ||
component.unmount() | ||
expect(onMock.mock.calls.length).toBe(3) | ||
expect(offMock.mock.calls.length).toBe(3) | ||
expect(onMock.mock.calls[0][1]).toBe(offMock.mock.calls[0][1]) | ||
expect(onMock.mock.calls[1][1]).toBe(offMock.mock.calls[1][1]) | ||
expect(onMock.mock.calls[2][1]).toBe(offMock.mock.calls[2][1]) | ||
}) | ||
|
||
it('when the path changes a new listeners are created', () => { | ||
const {onMock, offMock, refMock, Firebase} = FirebaseMock() | ||
const List = ListFactory(Firebase) | ||
const component = create(createElement(List, {path: 'some path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[0][0]).toBe('some path') | ||
component.update(createElement(List, {path: 'some other path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[1][0]).toBe('some other path') | ||
expect(onMock.mock.calls.length).toBe(3 + 3) | ||
}) | ||
|
||
it('when the path changes the existing listeners are cleaned up', () => { | ||
const {onMock, offMock, refMock, Firebase} = FirebaseMock() | ||
const List = ListFactory(Firebase) | ||
const component = create(createElement(List, {path: 'some path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[0][0]).toBe('some path') | ||
component.update(createElement(List, {path: 'some other path'}, | ||
(list) => `list: ${JSON.stringify(list)}` | ||
)) | ||
expect(refMock.mock.calls[1][0]).toBe('some other path') | ||
expect(onMock.mock.calls.length).toBe(3 + 3) | ||
expect(offMock.mock.calls.length).toBe(3) | ||
expect(onMock.mock.calls[0][1]).toBe(offMock.mock.calls[0][1]) | ||
expect(onMock.mock.calls[1][1]).toBe(offMock.mock.calls[1][1]) | ||
expect(onMock.mock.calls[2][1]).toBe(offMock.mock.calls[2][1]) | ||
}) | ||
}) |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters