Skip to content

[question] mocking out actions in a store #646

@andrusek

Description

@andrusek

howdy,
I know there is already a question posted regarding dynamically mocking out actions in a store where it is mentioned that the action could be replaced on the store instance. I was trying to do this something like this:

Howdy,
I was wondering if you could provide and example of how one would replace an action with a jest mock function by replacing the action on the instance of the store directly. I tried this and was getting errors:

TypeError: Cannot assign to read only property '...funciton name.....' of object '[object Object]'

So for example if I had a store like this:

testStore = types.model('testStore', {
name: types.string
}).actions((self) => {
function setName(aName) {
self.name = aName;
}

return {
setName
};
});

And say I had a jest test something like this:

it('testSomething', () => {
let aStore = TestStore.create({name: 'fred'});
aStore.setName = jest.fn()
:
})

this code would give me the error noted above. What would be the way to replace the method would it be in the when doing the create?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions