Skip to content

Instantly share code, notes, and snippets.

@RobbertWolfs
Last active October 15, 2015 16:59
Show Gist options
  • Select an option

  • Save RobbertWolfs/fde357daf24b2517de46 to your computer and use it in GitHub Desktop.

Select an option

Save RobbertWolfs/fde357daf24b2517de46 to your computer and use it in GitHub Desktop.

Revisions

  1. RobbertWolfs revised this gist Oct 15, 2015. 1 changed file with 6 additions and 13 deletions.
    19 changes: 6 additions & 13 deletions unit-testing.js
    Original file line number Diff line number Diff line change
    @@ -1,22 +1,15 @@
    it('should return objects', function() {

    var stub = sandbox.stub();
    var backend = {
    transfer: function(mails) {
    console.log(mails);
    }
    };
    stub.withArgs(backend).yieldsTo("transfer", [ { id: 123, to: 'peter.cosemans@gmail.com', body: 'aaaa...'}]);
    stub(backend);
    it('should return objects', function () {

    var backend = { transfer: sandbox.stub() };
    var stub2 = sandbox.stub(repository, 'getMails').returns([
    { id: 123, to: 'peter.cosemans@gmail.com', body: 'aaaa...'},
    { id: 123, to: 'wim.vanhoye@euri.com', body: 'bbb...'}
    {id: 123, to: 'peter.cosemans@gmail.com', body: 'aaaa...'},
    {id: 123, to: 'wim.vanhoye@euri.com', body: 'bbb...'}
    ]);

    mailSystem.transferEuriMails(backend);
    expect(stub2).to.have.been.called;
    var mails = stub2.returnValues[0][0];
    expect(mails).to.include.keys(['to', 'id', 'body']);

    expect(backend.transfer).to.have.been.called;

    });
  2. RobbertWolfs created this gist Oct 15, 2015.
    22 changes: 22 additions & 0 deletions unit-testing.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    it('should return objects', function() {

    var stub = sandbox.stub();
    var backend = {
    transfer: function(mails) {
    console.log(mails);
    }
    };
    stub.withArgs(backend).yieldsTo("transfer", [ { id: 123, to: 'peter.cosemans@gmail.com', body: 'aaaa...'}]);
    stub(backend);

    var stub2 = sandbox.stub(repository, 'getMails').returns([
    { id: 123, to: 'peter.cosemans@gmail.com', body: 'aaaa...'},
    { id: 123, to: 'wim.vanhoye@euri.com', body: 'bbb...'}
    ]);

    mailSystem.transferEuriMails(backend);
    expect(stub2).to.have.been.called;
    var mails = stub2.returnValues[0][0];
    expect(mails).to.include.keys(['to', 'id', 'body']);

    });