Created
August 16, 2015 02:12
-
-
Save pauleveritt/59bee84a5425bcb96d63 to your computer and use it in GitHub Desktop.
sinon-as-promises .then
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
import { expect } from "chai"; | |
import sinon from "sinon"; | |
import SinonAsPromised from "sinon-as-promised"; | |
function $q(resolve, reject) { | |
return new Promise(resolve, reject); | |
} | |
class Controller { | |
constructor($log, logs) { | |
this.$log = $log; | |
this.logs = logs; | |
this.logEntries = null; | |
} | |
getLogs(category, level) { | |
return this.logs.getLogs(category, level) | |
.then( | |
(response) => { | |
console.log("Response in controller", response); | |
this.logs = response; | |
}, | |
(error) => { | |
console.log("ERRRRRR"); | |
} | |
) | |
} | |
} | |
var $log = sinon.stub(); | |
describe("Logs Controller methods", () => { | |
var sandbox, logs, ctrl; | |
beforeEach(() => { | |
sandbox = sinon.sandbox.create(); | |
logs = {}; | |
ctrl = new Controller($log, logs); | |
}); | |
afterEach(() => { | |
sandbox.restore(); | |
}); | |
it("can call log data with success", () => { | |
logs.getLogs = sinon.stub().resolves(3); | |
ctrl.getLogs("category1", "level1") | |
.then(() => { | |
console.log("From test .then()"); | |
expect(1).to.be(2); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment