How can I share scope in SinonJs.
Here is my snippet for your reference:
// set up the mock
beforeEach(() => {
MockHomeApiService = function () {
return {
requestForEarlyAccess: ()=>{
console.log("homeApiService.requestForEarlyAccess");
}
}
};
MockTranslate = function () {
return sinon.stub().resolves("true");
};
});
// set up the angular mocks
beforeEach(() => {
// provide the
module(($provide) => {
$provide.service('homeApiService', MockHomeApiService);
$provide.service('$translate', MockTranslate);
});
// you can surround any injected dependencies with _ _ and // the injector will throw them away, it's just to // differentiate between variables that you might want to // use for tests.
inject((_$q_, _$timeout_, _homeApiService_, _$translate_) => {
$q = _$q_
// having $timeout is often useful for testing that
// promises have been fulfilled
$timeout = _$timeout_;
// set up sinon-as-promised, otherwise it won't work!
sinonAsPromised($q);
homeApiService = _homeApiService_;
$translate = _$translate_
});
});
// set up your controller using mocked dependencies
beforeEach(() => {
controller = new ApplyController(homeApiService, userAlertsService, $log, $translate);
});
Aucun commentaire:
Enregistrer un commentaire