Skip to content

Commit

Permalink
replaced naughty test pollution solution with better one
Browse files Browse the repository at this point in the history
  • Loading branch information
svidgen committed Jun 8, 2022
1 parent ffaa06b commit eadb5fc
Showing 1 changed file with 4 additions and 21 deletions.
25 changes: 4 additions & 21 deletions packages/datastore/__tests__/DataStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ describe('DataStore observeQuery, with fake-indexeddb and fake sync', () => {
Post: PersistentModelConstructor<Post>;
});

// This prevents pollution between tests. DataStore may have processes in
// flight that need to settle. If we stampede ahead before we do this,
// we can end up in very goofy states when we try to re-init the schema.
await DataStore.stop();
await DataStore.start();
await DataStore.clear();

Expand All @@ -296,27 +300,6 @@ describe('DataStore observeQuery, with fake-indexeddb and fake sync', () => {
(DataStore as any).syncPageSize = 1000;
});

afterEach(async () => {
//
// ~~~~ NAUGHTINESS WARNING! ~~~~
//
// ( cover your eyes )
//
// this prevents pollution between tests that may include observe() calls.
// This is a cheap solution let DataStore "settle" before clearing it and
// starting the next test. If we don't do this, we get "spooky"
// contamination between tests.
//
// NOTE: If you know of a better way to isolate these tests, please
// replace this pause!
//
await pause(10);

// an abundance of caution
await DataStore.start();
await DataStore.clear();
});

test('publishes preexisting local data immediately', async done => {
try {
for (let i = 0; i < 5; i++) {
Expand Down

0 comments on commit eadb5fc

Please sign in to comment.