application/__tests__/services/noteComment-service-test.js
jest.unmock('./../../services/base-service');
jest.unmock('./../../services/noteComment-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 {NoteCommentService, NoteCommentsStore} from './../../services/noteComment-service';
import fetch from './../../util/mock-fetch';
describe('NoteCommentService', () => {
let spies = {};
beforeEach(() => {
sinon.stub(window, 'fetch').returns(fetch({
'items': [
{
id: 1,
uuid: '123-456'
}
]
}));
spies.updateComments = sinon.spy(NoteCommentService, 'updateComments');
});
afterEach(() => {
NoteCommentService.updateComments.restore();
window.fetch.restore();
});
it('expects create to update', (done) => {
return NoteCommentService.createAndFetch('123', {'foo': 'bar'}).then(() => {
expect(spies.updateComments.called).toEqual(true);
expect(NoteCommentsStore.getState().comments.size).toBeGreaterThan(0);
done();
});
});
it('expects fetch to update', (done) => {
return NoteCommentService.fetch('123').then(() => {
expect(spies.updateComments.called).toEqual(true);
expect(NoteCommentsStore.getState().comments.size).toBeGreaterThan(0);
done();
});
});
});