调用Dispatcher.register返回`undefined`

时间:2016-03-25 12:25:07

标签: flux jestjs

Jest的新手,无法启动和运行。致电Dispatcher.register时,我得到的只是undefined

我正在运行Node.js 5.7.0和Jest 0.9.2。

以下测试失败:

BookedServicesStore-test.js

jest.unmock("../BookedServicesStore");
jest.unmock("object-assign");

describe("BookedServicesStore", () => {
  let BookedServicesStore;
  let AppDispatcher;

  beforeEach(() => {
    BookedServicesStore = require("../BookedServicesStore");
    AppDispatcher = require("../../dispatcher/AppDispatcher");
  });

  it("has a dispatch token", () => {
    expect(BookedServicesStore.dispatchToken).not.toBeUndefined();
  });
});

BookedServicesStore.js

import AppDispatcher from "../dispatcher/AppDispatcher";
import { EventEmitter } from "events";
import assign from "object-assign";

const CHANGE_EVENT = "change";

const BookedServicesStore = assign({}, EventEmitter.prototype, {
  emitChange() {
    this.emit(CHANGE_EVENT);
  },

  addChangeListener(callback) {
    this.on(CHANGE_EVENT, callback);
  },

  removeChangeListener(callback) {
    this.removeListener(CHANGE_EVENT, callback);
  }

  // ...
});

BookedServicesStore.dispatchToken = AppDispatcher.register(action => {
  // ...
});

module.exports = BookedServicesStore;

AppDispatcher.js

import { Dispatcher } from "flux";
module.exports = new Dispatcher();

不确定这里发生了什么。我错过了什么?

0 个答案:

没有答案