#169: remove unhandled promise rejections in tests. Added loging for that cases

This commit is contained in:
SleepWalker
2016-12-06 23:08:51 +02:00
parent febd148b2e
commit f9ae7053d0
18 changed files with 67 additions and 40 deletions

View File

@@ -126,7 +126,7 @@ describe('components/accounts/actions', () => {
sessionStorage.removeItem(expectedKey);
return authenticate(account)(dispatch).then(() => {
expect(sessionStorage.getItem(expectedKey), 'not to be null')
expect(sessionStorage.getItem(expectedKey), 'not to be null');
sessionStorage.removeItem(expectedKey);
});
});

View File

@@ -1,4 +1,5 @@
import expect from 'unexpected';
import sinon from 'sinon';
import { routeActions } from 'react-router-redux';
@@ -56,24 +57,15 @@ describe('components/user/actions', () => {
});
});
it('should post to /api/authentication/logout with user jwt', () => {
// TODO: need an integration test with a middleware, because this
// test is not reliable to check, whether logout request will have token inside
request.post.returns(new Promise((resolve) => {
setTimeout(() => {
// we must not overwrite user's token till request starts
expect(dispatch, 'was not called');
resolve();
}, 0);
}));
return callThunk(logout).then(() => {
it('should post to /api/authentication/logout with user jwt', () =>
callThunk(logout).then(() => {
expect(request.post, 'to have a call satisfying', [
'/api/authentication/logout', {}, {}
'/api/authentication/logout', {}, {
token: expect.it('not to be empty')
}
]);
});
});
})
);
testChangedToGuest();
testAccountsReset();

View File

@@ -2,14 +2,14 @@ import expect from 'unexpected';
describe('promise.prototype.finally', () => {
it('should be invoked after promise resolved', () =>
expect(new Promise((resolve) => {
expect(new Promise((resolve) =>
Promise.resolve().finally(resolve)
}), 'to be fulfilled')
), 'to be fulfilled')
);
it('should be invoked after promise rejected', () =>
expect(new Promise((resolve) => {
Promise.reject().finally(resolve)
}), 'to be fulfilled')
expect(new Promise((resolve) =>
expect(Promise.reject().finally(resolve), 'to be rejected')
), 'to be fulfilled')
);
});

View File

@@ -1,3 +1,5 @@
import sinon from 'sinon';
import AcceptRulesState from 'services/authFlow/AcceptRulesState';
import CompleteState from 'services/authFlow/CompleteState';
@@ -50,7 +52,8 @@ describe('AcceptRulesState', () => {
describe('#resolve', () => {
it('should call acceptRules', () => {
expectRun(mock, 'acceptRules').returns({then() {}});
expectRun(mock, 'acceptRules')
.returns(Promise.resolve());
state.resolve(context);
});

View File

@@ -1,3 +1,5 @@
import sinon from 'sinon';
import ActivationState from 'services/authFlow/ActivationState';
import CompleteState from 'services/authFlow/CompleteState';
import ResendActivationState from 'services/authFlow/ResendActivationState';
@@ -73,7 +75,7 @@ describe('ActivationState', () => {
mock,
'activate',
sinon.match.same(payload)
).returns({then() {}});
).returns(Promise.resolve());
state.resolve(context, payload);
});

View File

@@ -1,3 +1,5 @@
import sinon from 'sinon';
import LoginState from 'services/authFlow/LoginState';
import PasswordState from 'services/authFlow/PasswordState';
@@ -52,7 +54,7 @@ describe('LoginState', () => {
mock,
'login',
sinon.match.same(payload)
).returns({then() {}});
).returns(Promise.resolve());
state.resolve(context, payload);
});

View File

@@ -1,3 +1,5 @@
import sinon from 'sinon';
import RecoverPasswordState from 'services/authFlow/RecoverPasswordState';
import CompleteState from 'services/authFlow/CompleteState';
import LoginState from 'services/authFlow/LoginState';
@@ -67,7 +69,7 @@ describe('RecoverPasswordState', () => {
mock,
'recoverPassword',
sinon.match(expectedPayload)
).returns({then() {}});
).returns(Promise.resolve());
state.resolve(context, expectedPayload);
});

View File

@@ -1,3 +1,5 @@
import sinon from 'sinon';
import RegisterState from 'services/authFlow/RegisterState';
import CompleteState from 'services/authFlow/CompleteState';
import ActivationState from 'services/authFlow/ActivationState';
@@ -52,7 +54,7 @@ describe('RegisterState', () => {
mock,
'register',
sinon.match.same(payload)
).returns({then() {}});
).returns(Promise.resolve());
state.resolve(context, payload);
});

View File

@@ -1,3 +1,5 @@
import sinon from 'sinon';
import ResendActivationState from 'services/authFlow/ResendActivationState';
import CompleteState from 'services/authFlow/CompleteState';
import ActivationState from 'services/authFlow/ActivationState';
@@ -69,7 +71,7 @@ describe('ResendActivationState', () => {
mock,
'resendActivation',
sinon.match.same(payload)
).returns({then() {}});
).returns(Promise.resolve());
state.resolve(context, payload);
});