Testing stores
Test a store with plain Python, and check what a view did to it in a headless test.
janelkit-store Shared application data: stores with actions, controlled writes and change tracking, one instance per application, and persistence. pip install janelkit-storeThe logic, without Qt
A loose instance, Store(), needs no application: call its actions and check its fields with plain asserts, as in the examples of Controlled writes and Tracking changes. Keep most tests there; they are fast and point at the exact rule that broke.
What a view did to the store
When imported, the package adds two methods to janelkit.inspect: app.store(Class, key=None) returns the instance of the mounted application, and app.mutations() its mutations, from the oldest to the newest. Each mount starts with fresh instances and an empty temporary data folder.
# tests/test_cart.py, for the example in Overview.
from janelkit.inspect import mount
from stores.cart import Cart
def test_add_an_apple():
with mount("src/App.janel") as app:
app.find("button", text="Add an apple").click()
assert len(app.store(Cart).items) == 1
assert [m.action for m in app.mutations()] == ["add"]CopyHow it works
- The click goes through the real button, like a user.
- app.store(Cart) is the same instance the views use.
- The list of actions shows that the view changed the store through add, not directly.
Examples
apps/examples/carrito, in the JanelKit repository, shares one strict store between two windows and logs every change. apps/examples/preferencias remembers preferences with persisted.
English documentation based on the JanelKit source. For additional details, browse the source docs ↗.