// @flow
import { act } from 'react-dom/test-utils';

window.matchMedia = _query => ({
  _matches: false,
  // $FlowFixMe - Flow doesn't like getters or setters
  get matches() {
    return this._matches;
  },
  // $FlowFixMe - Flow doesn't like getters or setters
  set matches(newValue) {
    const hasChanged = newValue !== this._matches;
    this._matches = newValue;
    if (hasChanged) {
      act(() => {
        this.listeners.forEach(listener => listener());
      });
    }
  },

  listeners: new Set(),
  addListener(listener) {
    this.listeners.add(listener);
  },
});
