-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: set loading state as false before return data in @effect * feat: keep the bean alive witch provided in StatedBeanProvider * test: add some unit test
- Loading branch information
Showing
18 changed files
with
220 additions
and
95 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
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
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
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
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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { | ||
BeanDefinition, | ||
IBeanFactory, | ||
StatedBeanApplication, | ||
StatedBeanProvider, | ||
StatedBeanConsumer, | ||
StatedBeanContextValue, | ||
} from '../src'; | ||
|
||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
|
||
describe('StatedBeanApplication', () => { | ||
it('application bean factory test', () => { | ||
const application = new StatedBeanApplication(); | ||
|
||
class CustomBeanFactory implements IBeanFactory { | ||
createBean<T>(beanDefinition: BeanDefinition<T>): T { | ||
// eslint-disable-next-line new-cap | ||
return new beanDefinition.beanType(); | ||
} | ||
|
||
destroyBean() { | ||
// | ||
} | ||
} | ||
|
||
const beanFactory = new CustomBeanFactory(); | ||
application.setBeanFactory(beanFactory); | ||
|
||
expect(application.getBeanFactory() === beanFactory).toEqual(true); | ||
}); | ||
|
||
it('StatedBeanConsumer test', () => { | ||
const application = new StatedBeanApplication(); | ||
const Sample = () => ( | ||
<StatedBeanConsumer> | ||
{(context: StatedBeanContextValue) => { | ||
expect(context).not.toBeNull(); | ||
expect(context.container).not.toBeNull(); | ||
expect(context.container!.application).toBe(application); | ||
return null; | ||
}} | ||
</StatedBeanConsumer> | ||
); | ||
|
||
const App = () => ( | ||
<StatedBeanProvider application={application}> | ||
<Sample /> | ||
</StatedBeanProvider> | ||
); | ||
|
||
const div = document.createElement('div'); | ||
ReactDOM.render(<App />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); | ||
}); |
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,32 @@ | ||
import { renderHook, act } from '@testing-library/react-hooks'; | ||
|
||
import { StatedBeanProvider, useBean } from '../src'; | ||
|
||
import React from 'react'; | ||
|
||
const PlanObjectBean = { | ||
count: 0, | ||
add() { | ||
this.count++; | ||
}, | ||
}; | ||
|
||
describe('props observer test', () => { | ||
it('Props init value test', () => { | ||
const wrapper = ({ children }: { children: React.ReactNode }) => ( | ||
<StatedBeanProvider>{children}</StatedBeanProvider> | ||
); | ||
|
||
const { result } = renderHook( | ||
() => { | ||
return useBean(() => PlanObjectBean); | ||
}, | ||
{ wrapper }, | ||
); | ||
expect(result.current.count).toBe(0); | ||
act(() => { | ||
result.current.add(); | ||
}); | ||
expect(result.current.count).toBe(1); | ||
}); | ||
}); |
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
Oops, something went wrong.