2016-06-10 10:36:21 +05:30
|
|
|
/**
|
|
|
|
* A helpers for testing states in isolation from AuthFlow
|
|
|
|
*/
|
|
|
|
|
2017-01-29 17:12:51 +05:30
|
|
|
import sinon from 'sinon';
|
|
|
|
|
2016-03-21 11:46:37 +05:30
|
|
|
export function bootstrap() {
|
2019-11-27 14:33:32 +05:30
|
|
|
const context = {
|
|
|
|
getState: sinon.stub(),
|
|
|
|
run() {},
|
|
|
|
setState() {},
|
|
|
|
getRequest: sinon.stub(),
|
|
|
|
navigate() {},
|
|
|
|
};
|
|
|
|
|
|
|
|
const mock = sinon.mock(context);
|
|
|
|
mock.expects('run').never();
|
|
|
|
mock.expects('navigate').never();
|
|
|
|
mock.expects('setState').never();
|
|
|
|
|
|
|
|
return { context, mock };
|
2016-03-21 11:46:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
export function expectState(mock, state) {
|
2019-11-27 14:33:32 +05:30
|
|
|
return mock
|
|
|
|
.expects('setState')
|
|
|
|
.once()
|
|
|
|
.withExactArgs(sinon.match.instanceOf(state));
|
2016-03-21 11:46:37 +05:30
|
|
|
}
|
|
|
|
|
2016-08-27 20:06:33 +05:30
|
|
|
export function expectNavigate(mock, route, options) {
|
2019-11-27 14:33:32 +05:30
|
|
|
if (options) {
|
|
|
|
return mock
|
|
|
|
.expects('navigate')
|
|
|
|
.once()
|
|
|
|
.withExactArgs(route, sinon.match(options));
|
|
|
|
}
|
|
|
|
|
|
|
|
return mock
|
|
|
|
.expects('navigate')
|
|
|
|
.once()
|
|
|
|
.withExactArgs(route);
|
2016-03-21 11:46:37 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
export function expectRun(mock, ...args) {
|
2019-11-27 14:33:32 +05:30
|
|
|
return mock
|
|
|
|
.expects('run')
|
|
|
|
.once()
|
|
|
|
.withExactArgs(...args);
|
2016-03-21 11:46:37 +05:30
|
|
|
}
|