These are chat archives for reflux/refluxjs

20th
Jul 2015
Egor Gumenyuk
@boo1ean
Jul 20 2015 16:40
Are components should listen stores only?
Iliyan Betovski
@ibetovski
Jul 20 2015 21:43

Hello. I am trying TDD with Jest and Reflux.
Doesn't look like something too complicated but I am not able to trigger the Store's listener on the action.
Can somebody help me because I am in a dead end already.
Skip the "expect" assertions in the code, I don't see the console logs that I put there for debugging if the store's functions are invoked at all.
Here is the test:

jest.dontMock('../app/actions/ListActions.js');
jest.dontMock('../app/stores/ListStore.js');

describe('List', function() {
  var React;
  var Store;
  var Actions;
  var TestUtils;

  beforeEach(function() {
    Actions = require('../app/actions/ListActions.js');
    Store = require('../app/stores/ListStore.js');
  });
  it('should add todo to the list', function() {
    // this is supposed to trigger the Store's listener but it doesn't
    Actions.addItem({
      text: "To do something"
    });
  });
});

And here is the Store:

var Reflux = require('reflux');
var ListActions = require('../actions/ListActions.js');

var ListStore = Reflux.createStore({
  listenables: ListActions, // tried with  [ListAction] but without any success

  onAddItem: function() {
    console.log('--------------------------234234');
  },

// checked if there was a problem with the names of the functions.
  addItem: function() {
    console.log('============sdfsdf');
  }

});

module.exports = ListStore;

Here is the entire test file: https://github.com/ibetovski/tdd-with-jest-and-react/blob/master/__tests__/list.spec.js
Here is the store file: https://github.com/ibetovski/tdd-with-jest-and-react/blob/master/app/stores/ListStore.js

Iliyan Betovski
@ibetovski
Jul 20 2015 21:59
And here is the Actions file:
var Reflux = require('reflux');
var ListActions = Reflux.createActions([
  'addItem'
]);

module.exports = ListActions;