Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Add testing for 'utils' module
Browse files Browse the repository at this point in the history
  • Loading branch information
woshilapin committed Nov 4, 2016
1 parent 40e33e7 commit c202948
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion test/configure.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ describe(`[module] configure`, function() {
"notapath": `/not/a/path`
};
let answer = `42`;
let createInterface;
before(function(done) {
mockfs({
[filepath]: filecontent
Expand All @@ -87,6 +86,7 @@ describe(`[module] configure`, function() {
}
});
let sandbox;
let createInterface;
beforeEach(function() {
sandbox = sinon.sandbox.create()
createInterface = sandbox.stub(readline, 'createInterface', function() {
Expand Down
29 changes: 25 additions & 4 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,15 @@ chai.use(sinonchai);

describe(`[module] utils`, function() {
describe(`[method] kill`, function() {
let exit;
let sandbox;
beforeEach(function() {
exit = sinon.stub(process, `exit`);
sandbox = sinon.sandbox.create();
});
afterEach(function() {
exit.restore();
sandbox.restore();
});
it(`should call process.exit with an negative value`, mute(function() {
let exit = sandbox.stub(process, `exit`);
let message = `Some error message`;
utils.kill(new Error(message));
expect(exit).to.have.been.calledOnce;
Expand Down Expand Up @@ -53,7 +54,7 @@ describe(`[module] utils`, function() {
]);
});
it(`should reject after 3 tries if authentication failed`, mute(function() {
login = sandbox.stub(cgapi, `login`, function() {
let login = sandbox.stub(cgapi, `login`, function() {
return Promise.resolve({
"error": new Error(`Cannot authenticate`)
});
Expand All @@ -71,5 +72,25 @@ describe(`[module] utils`, function() {
}));
});
describe(`[method] tests`, function() {
let sandbox;
beforeEach(function() {
sandbox = sinon.sandbox.create();
});
afterEach(function() {
sandbox.restore();
});
it(`should yield a result for each of the 3 tests`, async function() {
let parameters = {
"exercise": `aaa`,
"tests": [1, 2, 3],
"language": `Python`,
"bundle": `print('Hello world!')`
};
let test = sandbox.stub(cgapi, `test`, function() {return Promise.resolve(true)});
for await (let result of utils.tests(parameters)) {
expect(result).to.have.be.ok;
}
expect(test).to.have.callCount(3);
});
});
});

0 comments on commit c202948

Please sign in to comment.