Nozbe / WatermelonDB

🍉 Reactive & asynchronous database for powerful React and React Native apps ⚡️
https://watermelondb.dev
MIT License
10.49k stars 589 forks source link

Test a watermelondb #155

Closed popo63301 closed 5 years ago

popo63301 commented 5 years ago

Hi guys !

This project looks amazing. I would like to know if you have planned to help people test a watermelonDB? As it requires an interaction with a local SQLite DB or Indexeddb, how about creating an official mock for watermelonDB so that people can test their app using Jest?

radex commented 5 years ago

@popo63301 Testing with Jest works :)

radex commented 5 years ago

closing this; let me know if you're having troubles running Watermelon in Jest env

popo63301 commented 5 years ago

@radex Thank you ! I'll try to experiment it when I have time. 😄

sidferreira commented 4 years ago

Not working for me :/

lucianomlima commented 3 years ago

@radex can give an example? How to mock?

stylder commented 3 years ago

.

JeandeCampredon commented 3 years ago

Any news on that ?

sidferreira commented 3 years ago

Will share a workaround later

yan-brito commented 2 years ago

hi guys, can someone give a mock example please?

filipepiresg commented 1 year ago

hi guys, can someone give a mock example please?

craigmulligan commented 1 year ago

I've been using the node.js adapter mocking it via jest.

jest.mock(
  '@nozbe/watermelondb/adapters/sqlite/makeDispatcher/index.native.js',
  () => {
    return jest.requireActual(
      '@nozbe/watermelondb/adapters/sqlite/makeDispatcher/index.js',
    );
  },
);

It's been working great! You can see some notes on my full setup here: https://craigmulligan.com/posts/testing-with-watermelon/

Happy to submit a PR for docs or a jest module folks can include to automatically do the mocking if the maintainers are interested?

shahulul1 commented 3 months ago

I am getting Error when I using const syncStoreMaster = database.get('sync_store_master'), jest.spyOn(syncStoreMaster,'query').mockImplementations(()=> Promise.resolve([])) Cannot use spyOn on a primitive value; undefined given? anyone can give an example for mocking data in the table ?

craigmulligan commented 3 months ago

@shahulul1, have you tried mocking it with sqlite3? see my comment above