Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isMember(req, res, next) {
- MyService.GetUserAsync(authCookie)
- .then(function (user) {
- next();
- })
- .catch(function (err) {
- if (err.status === 400) {
- return res.redirect("/notAllowed");
- }
- else {
- return next(err);
- }
- });
- }
- beforeEach(function () {
- // Overwrite the global timer functions (setTimeout, setInterval) with Sinon fakes
- this.clock = sinon.useFakeTimers();
- });
- afterEach(function () {
- // Restore the global timer functions to their native implementations
- this.clock.restore();
- });
- it.only("pass authentication and set authCookie", function (done) {
- var user = {
- userNameField: "fakeUserName"
- };
- sinon.stub(MyService, "GetUserAsync").returns(Promise.resolve(user));
- var spyCallback = sinon.spy();
- var req {};
- var res = {};
- isMember(req, res, spyCallback);
- // Not waiting here!
- this.clock.tick(1510);
- // spyCallback.called is always false
- expect(spyCallback.called).to.equal(true);
- done();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement