Skip to content

Commit

Permalink
Improved test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
manuel committed Mar 17, 2017
1 parent aee90c1 commit 635ceb9
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion src/service/redirect-output.service.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,23 @@

describe('Service: ReedirectOutput', () => {
logger.setLogLevel(3);
let fsStub, errorStub, infoStub;

beforeEach(() => {
fsStub = sinon.stub(fs, 'writeFile');
errorStub = sinon.stub(logger, 'error');
infoStub = sinon.stub(logger, 'info');
fsStub.reset();
errorStub.reset();
infoStub.reset();
});

afterEach(() => {
errorStub.restore();
fsStub.restore();
infoStub.restore();
})

it('should be defined', () => {
expect(!!service).to.equal(true);
});
Expand All @@ -29,11 +46,38 @@
let params = new Parameters();
params.output = '.';

let fsStub = sinon.stub(fs, 'writeFile');
service.redirectOutput('asdf', params);

fsStub.restore();
expect(fsStub.called).to.equal(true);
})

it('should call logger error in case of writeFile error', () => {
let params = new Parameters();
params.output = '.';

fsStub.yields( new Error('error'));

service.redirectOutput('asdf', params);

errorStub.restore();
fsStub.restore();
expect(fsStub.called).to.equal(true);
expect(errorStub.called).to.equal(true);
})

it('should call logger info in case of writeFile success', () => {
let params = new Parameters();
params.output = '.';

fsStub.yields(null);

service.redirectOutput('asdf', params);

errorStub.restore();
infoStub.restore();
expect(fsStub.called).to.equal(true);
expect(infoStub.called).to.equal(true);
})
})
})
Expand Down

0 comments on commit 635ceb9

Please sign in to comment.