Home Reference Source

application/__tests__/services/error-service-test.js

jest.unmock('./../../services/base-service');
jest.unmock('./../../services/error-service');

jest.unmock('./../../alt');

import React from 'react';
import ReactDOM from 'react-dom';
import TestUtils from 'react-addons-test-utils';
import Immutable from 'immutable';
import sinon from 'sinon';
import AltTestingUtils from 'alt-utils/lib/AltTestingUtils';

import alt from './../../alt';
import {ErrorService, ErrorsStore} from './../../services/error-service';

describe('ErrorService', () => {
    let spies = {};

    beforeEach(() => {
        spies.add = sinon.spy(ErrorService, 'add');
        ErrorService.add('error', 'foo');

        jasmine.clock().uninstall();
        jasmine.clock().install();
    });

    afterEach(() => {
        ErrorService.add.restore();
        jasmine.clock().uninstall();
    });

    it('expects add to be called', (done) => {
        expect(spies.add.calledOnce).toEqual(true);
        return done();
    })

    it('expects update to be called', (done) => {
        ErrorService.add('error', 'foo');
        jasmine.clock().tick(2);
        process.nextTick(() => {
            expect(ErrorsStore.getState().error.message).toEqual('foo');
            return done();
        });
    });

});