Reputation: 9435
Say I wish to test if the "loading" property is set during the execution of tests:
export const MyModel = types
.model("MyModel", {
frontendId: types.optional(types.identifier, () => v4()), // id only for frontend
id: types.maybeNull(types.identifier, () => v4()),
loading: types.optional(types.boolean, false),
})
.actions((self) => ({
load: flow(function* load(env) {
self.loading = true;
yield env.jsonFetch("someurl")
self.loading = false;
}),
}))
test("Load data from", async () => {
const model = MyModel.create({}, {
jsonFetch: () => {
console.log('fetch called');
}
});
await model.load(); // How would I test during this call that the store has set something correctly?
}
Upvotes: 0
Views: 5