jeudi 17 novembre 2016

how to write a test for Javascript

I am attempting to write a test for this code but I am having problems.

const attemptFinish = (TaskId, then) => (disp) => {
return Api
    .finishTask(TaskId)
    .then(then);
};
export default attemptFinish;

the finishtask function is like so

finishTask(TaskId) {
    return ajaClass
        .post(host + '/comptask/mark', {
            id: TaskId
        });
}

I am currently using Sinon to try and create a response that will be used for the results. It also has a promise which makes it more complex

describe ("attemptFinish assess actions", () => {
var participantID = 145;
var prom = new Promise((resolve, reject) => {
resolve();
});

it("should return", () => {
    var astub = sinon.stub(Api, "finishTask")
    astub.withArgs(participantID, " ");
    var callback = sinon.spy();

    attemptFinish(participantID, prom)
    astub.restore();
});
});

Aucun commentaire:

Enregistrer un commentaire