0

I'm using "ava" framework for react testing, here is a piece of package.json:

  "babel": {
    "presets": [
      "es2015",
      "stage-2",
      "react"
    ]
  },
  "ava": {
    "babel": "inherit",
    "require": [
      "babel-register"
    ]
  }

code of test:

import store from '../../app/redux/store';
 import test from 'ava';
import * as c from '../../app/constants'

test('languageReducer() should correctly change the dictionary', t => {
  store.dispatch({
    type: c.LOCALIZE_CHANGE_DICTIONARY,
    dictionary: {
      a: 1,
      b: 2,
      c: 3
    }
  });

  t.DeepEqual(store.getState().localizeReducer.dictionary, {a: 1, b: 2, c: 3});

  t.is(10, 10);
});

and there is error sounds like :

unsubscribeHistory = history.listen(function (location) {
                            ^

TypeError: Cannot read property 'listen' of undefined
    at middleware      (/Users/nikita/WebstormProjects/crm_panel/node_modules/redux-simple-  router/lib/index.js:72:33)

What should I do to give my tests access to global namespace(window, history, etc.) ? Thank you

Foker
  • 944
  • 2
  • 9
  • 22

1 Answers1

1

It seems you're trying to use a browser module, that tries to use the browser global history, without actually running the test in the browser. AVA doesn't yet run in the browser, but you can use jsdom to provide a fake browser environment. We have a recipe for this.

Sindre Sorhus
  • 62,972
  • 39
  • 168
  • 232