summaryrefslogtreecommitdiffstats
path: root/devtools/client/application/test/node/helpers.js
blob: 6699549a159e650f53acb2e0fdfb4531ab4964bc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

"use strict";

const {
  thunk,
} = require("resource://devtools/client/shared/redux/middleware/thunk.js");
const configureStore = require("redux-mock-store").default;

/**
 * Prepare the store for use in testing.
 */
function setupStore(preloadedState = {}) {
  const middleware = [thunk()];
  const mockStore = configureStore(middleware);
  return mockStore(preloadedState);
}

/**
 * This gives an opportunity to Promises to resolve in tests
 * (since they are microtasks)
 */
async function flushPromises() {
  await new Promise(r => setTimeout(r, 0));
}

module.exports = {
  flushPromises,
  setupStore,
};