Skip to content

Commit

Permalink
Enhance our LogicMounter helper to accept and build props
Browse files Browse the repository at this point in the history
  • Loading branch information
cee-chen committed Mar 9, 2021
1 parent 5d119cf commit 82ae123
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ export const setMockActions = (actions: object) => {
* const { mount, unmount } = new LogicMounter(SomeLogic);
*
* it('some test', () => {
* mount({ someValue: 'hello' });
* mount({ someValue: 'hello' }, { someProp: 'world' });
* unmount();
* });
*/
import { resetContext, Logic, LogicInput } from 'kea';

interface LogicFile {
inputs: Array<LogicInput<Logic>>;
build(props?: object): void;
mount(): Function;
}
export class LogicMounter {
Expand All @@ -110,8 +111,10 @@ export class LogicMounter {
};

// Automatically reset context & mount the logic file
public mount = (values?: object) => {
public mount = (values?: object, props?: object) => {
this.resetContext(values);
if (props) this.logicFile.build(props);

const unmount = this.logicFile.mount();
this.unmountFn = unmount;
return unmount; // Keep Kea behavior of returning an unmount fn from mount
Expand Down

0 comments on commit 82ae123

Please sign in to comment.