Home Reference Source

application/__tests__/util/events-test.js

jest.unmock('./../../util/events')

import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Events from './../../util/events';

describe('Events listen', () => {
    let callbacks;

    beforeEach(() => {
        callbacks = {
            callee: () => {
                return 'Foo';
            }
        };

        spyOn(callbacks, 'callee');

        Events.listen('onTest', callbacks.callee);
        Events.emit('onTest');

    });

    it('calls listener', () => {
        expect(callbacks.callee).toHaveBeenCalled();
    });
});

describe('Events unlisten', () => {
    let callbacks;

    beforeEach(() => {
        callbacks = {
            callee: () => {
                return 'Foo';
            }
        };

        spyOn(callbacks, 'callee');

        Events.listen('onTest', callbacks.callee);
        Events.unlisten('onTest', callbacks.callee);
        Events.emit('onTest');

    });

    it('calls listener', () => {
        expect(callbacks.callee).not.toHaveBeenCalled();
    });
});