Skip to main content

Unit Test

You can unit test your application directly against Replicache, without having to mock out Replicache's interface. To do so, there are a few considerations:

  • You'll need to run your tests in a web environment like web-test-runner, because Replicache has DOM dependencies.
  • You should use TEST_LICENSE_KEY for your license during automated tests to prevent inflated usage.
  • You'll want to disable sync. You can do this with any of:
    • Set pullURL and pushURL to undefined. These are read/write so clearing them prevents next push/pull.
    • Set a large delay: setting a large pushDelay will prevent automatically pushing after a mutation. Setting pullInterval will increase the time to the next pull.
    • You could implement a custom puller/pusher.
  • You may want to run Replicache in-memory. This can be done by setting the experimentalCreateKVStore parameter to name => new ExperimentalMemKVStore(name). See ExperimentalMemKVStore for more information.
    • Alternately, you can keep using the persistent storage and pick a randomly-generated name for your Replicache instance each time you create it.