Skip to content
This repository has been archived by the owner on Sep 27, 2022. It is now read-only.

Commit

Permalink
fixed iteration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jwoos committed Aug 20, 2016
1 parent 62b9899 commit 4225567
Showing 1 changed file with 16 additions and 19 deletions.
35 changes: 16 additions & 19 deletions test/unit/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ describe('Class: DFrotzInterface', () => {

let promise = frotz.checkForSaveFile();

promise.finally(() => {
promise.catch(() => {
expect(promise.isRejected()).toEqual(true);
});
});
Expand Down Expand Up @@ -402,7 +402,7 @@ describe('Class: DFrotzInterface', () => {
});
});

xdescribe('Method: iteration', () => {
describe('Method: iteration', () => {
let frotz, mockFunction, mockDefers;

beforeEach(() => {
Expand All @@ -414,7 +414,9 @@ describe('Class: DFrotzInterface', () => {
};

spyOn(frotz, 'checkForSaveFile').and.returnValues(mockDefers.checkForSaveFile.promise);
spyOn(frotz, 'init');
spyOn(frotz, 'init').and.callFake(() => {
frotz.dfrotz = {};
});
spyOn(frotz, 'restoreSave').and.returnValues(mockDefers.restoreSave.promise);
spyOn(frotz, 'command');
spyOn(frotz, 'writeSave');
Expand All @@ -425,6 +427,9 @@ describe('Class: DFrotzInterface', () => {
let result = frotz.iteration('look', mockFunction);
let saveFileExists = true;

mockDefers.checkForSaveFile.resolve(saveFileExists);
mockDefers.restoreSave.resolve();

result.then(() => {
expect(frotz.checkForSaveFile).toHaveBeenCalled();
expect(frotz.init).toHaveBeenCalledWith(mockFunction);
Expand All @@ -435,26 +440,18 @@ describe('Class: DFrotzInterface', () => {

done();
});

mockDefers.checkForSaveFile.resolve(saveFileExists);
mockDefers.restoreSave.resolve();
});

it('should throw error if no command', (done) => {
frotz.iteration('', mockFunction);
let saveFileExists = true;

mockDefers.checkForSaveFile.resolve(saveFileExists);
mockDefers.restoreSave.resolve();
it('should handle promise rejections', (done) => {
spyOn(console, 'error');
let result = frotz.iteration('look', mockFunction);

expect(frotz.checkForSaveFile).toHaveBeenCalled();
expect(frotz.init).toHaveBeenCalledWith(mockFunction);
expect(frotz.restoreSave).toHaveBeenCalledWith(saveFileExists);
expect(bluebird.delay).toHaveBeenCalledWith(100);
expect(frotz.command).toHaveBeenCalledWith('look');
expect(frotz.writeSave).toHaveBeenCalled();
mockDefers.checkForSaveFile.reject();

done();
result.finally(() => {
expect(console.error).toHaveBeenCalled();
done();
});
});
});
});

0 comments on commit 4225567

Please sign in to comment.