<commit_before>import * as Store from '../store'
import { VisibilityFilters } from '../../actions/constants'
import { addTodo } from '../../actions/todo'
import localStorageMock from '../../__mocks__/localStorage'

describe('App Store', () => {

  beforeEach(() => {
    window.localStorage = localStorageMock;
  })

  afterEach(() => {
    localStorage && localStorage.clear();
  })

  it('should return a store with the initial default state for the app', () => {
    let store = Store.configure();
    expect(store.getState()).toEqual({
      todos: {},
      visibilityFilter: VisibilityFilters.SHOW_ALL
    })
  })

  it('should allow delayed subscriptions to run after each state update', (async) => {
    jest.useFakeTimers();

    let mockFn = jest.fn();
    let store = Store.configure({
      subscriptions: [{
        fn: mockFn,
        delay: 0
      }]
    });
    let stateUpdates = new Promise((resolve, reject) => {
      setTimeout(() => {
        store.dispatch(addTodo('todo 1'))
        store.dispatch(addTodo('todo 2'))
        store.dispatch(addTodo('todo 3'))
        resolve()
      }, 2)
    });

    return stateUpdates.then(() => {
      // The subscription function will be called once though the state
      // was updated on three different occasions
      expect(mockFn).toHaveBeenCalledTimes(1);
      expect(Object.keys(store.getState().todos).length).toEqual(3);
    })
  })

})<commit_msg>redux: fix async test to test state subscriptions<commit_after>import * as Store from '../store'
import { VisibilityFilters } from '../../actions/constants'
import { addTodo } from '../../actions/todo'
import localStorageMock from '../../__mocks__/localStorage'

describe('App Store', () => {

  beforeEach(() => {
    window.localStorage = localStorageMock;
  })

  afterEach(() => {
    localStorage && localStorage.clear();
  })

  it('should return a store with the initial default state for the app', () => {
    let store = Store.configure();
    expect(store.getState()).toEqual({
      todos: {},
      visibilityFilter: VisibilityFilters.SHOW_ALL
    })
  })

  it('should allow delayed subscriptions to run after each state update', () => {
    jest.useRealTimers()

    let mockFn = jest.fn();
    let store = Store.configure({
      subscriptions: [{
        fn: mockFn,
        delay: 0
      }]
    });

    let stateUpdates = new Promise((resolve, reject) => {
      store.dispatch(addTodo('todo 1'))
      store.dispatch(addTodo('todo 2'))
      store.dispatch(addTodo('todo 3'))

      setTimeout(() => {
        resolve();
      }, 1)

    });

    return stateUpdates.then(() => {
      expect(Object.keys(store.getState().todos).length).toEqual(3);
      expect(mockFn).toHaveBeenCalledTimes(1);
    })
  });

})
{'fraction_non_alphanumeric': 0.15814290895901342, 'fraction_numerical': 0.005077983315197679, 'mean_word_length': 2.825242718446602, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4609126', 'n_tokens_mistral': 820, 'n_tokens_neox': 814, 'n_words': 192}