<commit_before>var testedModule = 'angular-meteor.reactive-scope';

describe('angular-meteor', function () {
  describe(testedModule, function () {
    var $compile;
    var $rootScope;
    var testScope;

    var helpersFuncSpy, autorunFuncSpy, subscribeFuncSpy, reactivePropertiesFuncSpy, attachFuncSpy, onPropertyChangedFuncSpy, stopFuncSpy;

    beforeEach(angular.mock.module(testedModule, function($provide) {
      $provide.factory('$reactive', function() {
        return function(context) {
          var fakedReactiveClass = function(context) {
            this.context = context;
          };

          helpersFuncSpy = fakedReactiveClass.prototype.helpers = jasmine.createSpy('helpers');
          attachFuncSpy = fakedReactiveClass.prototype.attach = jasmine.createSpy('attach');
          reactivePropertiesFuncSpy = fakedReactiveClass.prototype.reactiveProperties = jasmine.createSpy('reactiveProperties');
          onPropertyChangedFuncSpy = fakedReactiveClass.prototype.onPropertyChanged = jasmine.createSpy('onPropertyChanged');
          subscribeFuncSpy = fakedReactiveClass.prototype.subscribe = jasmine.createSpy('subscribe');
          autorunFuncSpy = fakedReactiveClass.prototype.autorun = jasmine.createSpy('autorun');
          stopFuncSpy = fakedReactiveClass.prototype.stop = jasmine.createSpy('stop');

          return new fakedReactiveClass(context);
        }
      })
    }));


    beforeEach(angular.mock.inject(function (_$compile_, _$rootScope_) {
      $compile = _$compile_;
      $rootScope = _$rootScope_;
      testScope = $rootScope.$new();
    }));

    it('Should extend any child scope that created from the $rootScope with the relevant API', function () {
      expect(typeof testScope.helpers).toBe('function');
      expect(typeof testScope.autorun).toBe('function');
      expect(typeof testScope.subscribe).toBe('function');
      expect(typeof testScope.getReactively).toBe('function');
      expect(typeof testScope.stopOnDestroy).toBe('function');
    });

    it('Should use the $reactive helpers function when using it', function() {
      testScope.helpers({
        test: function() {
          return 10;
        }
      });

      expect(helpersFuncSpy).toHaveBeenCalled();
    });

    it('Should use the Meteor autorun function when using it', function() {
      var meteorAutorunSpy = spyOn(Meteor, 'autorun');
      testScope.autorun(function() {});

      expect(meteorAutorunSpy).toHaveBeenCalled();
    });

    it('Should use the Meteor subscribe function when using it', function() {
      var mockedResult = {
        ready : jasmine.createSpy('ready'),
        stop : jasmine.createSpy('stop'),
        subscriptionId : '123'
      };
      var meteorSubscribeSpy = spyOn(Meteor, 'subscribe').and.returnValue(mockedResult);
      testScope.subscribe('', function() { return [] });

      expect(meteorSubscribeSpy).toHaveBeenCalled();
    });

    it('Should stop the subscription when calling stop on the return value', function() {
      var mockedResult = {
        ready : jasmine.createSpy('ready'),
        stop : jasmine.createSpy('stop'),
        subscriptionId : '123'
      };
      spyOn(Meteor, 'subscribe').and.returnValue(mockedResult);
      spyOn(Meteor, 'autorun').and.callFake(function(cb) {
        cb();
        return {stop: function() {mockedResult.stop()}};
      });
      var result = testScope.subscribe('', () => []);

      result.stop();
      result.ready();

      expect(mockedResult.stop).toHaveBeenCalled();<commit_msg>feat (subscribe):  fix tests when mocking autorun<commit_after>var testedModule = 'angular-meteor.reactive-scope';

describe('angular-meteor', function () {
  describe(testedModule, function () {
    var $compile;
    var $rootScope;
    var testScope;

    var helpersFuncSpy, autorunFuncSpy, subscribeFuncSpy, reactivePropertiesFuncSpy, attachFuncSpy, onPropertyChangedFuncSpy, stopFuncSpy;

    beforeEach(angular.mock.module(testedModule, function($provide) {
      $provide.factory('$reactive', function() {
        return function(context) {
          var fakedReactiveClass = function(context) {
            this.context = context;
          };

          helpersFuncSpy = fakedReactiveClass.prototype.helpers = jasmine.createSpy('helpers');
          attachFuncSpy = fakedReactiveClass.prototype.attach = jasmine.createSpy('attach');
          reactivePropertiesFuncSpy = fakedReactiveClass.prototype.reactiveProperties = jasmine.createSpy('reactiveProperties');
          onPropertyChangedFuncSpy = fakedReactiveClass.prototype.onPropertyChanged = jasmine.createSpy('onPropertyChanged');
          subscribeFuncSpy = fakedReactiveClass.prototype.subscribe = jasmine.createSpy('subscribe');
          autorunFuncSpy = fakedReactiveClass.prototype.autorun = jasmine.createSpy('autorun');
          stopFuncSpy = fakedReactiveClass.prototype.stop = jasmine.createSpy('stop');

          return new fakedReactiveClass(context);
        }
      })
    }));


    beforeEach(angular.mock.inject(function (_$compile_, _$rootScope_) {
      $compile = _$compile_;
      $rootScope = _$rootScope_;
      testScope = $rootScope.$new();
    }));

    it('Should extend any child scope that created from the $rootScope with the relevant API', function () {
      expect(typeof testScope.helpers).toBe('function');
      expect(typeof testScope.autorun).toBe('function');
      expect(typeof testScope.subscribe).toBe('function');
      expect(typeof testScope.getReactively).toBe('function');
      expect(typeof testScope.stopOnDestroy).toBe('function');
    });

    it('Should use the $reactive helpers function when using it', function() {
      testScope.helpers({
        test: function() {
          return 10;
        }
      });

      expect(helpersFuncSpy).toHaveBeenCalled();
    });

    it('Should use the Meteor autorun function when using it', function() {
      var meteorAutorunSpy = spyOn(Meteor, 'autorun');
      testScope.autorun(function() {});

      expect(meteorAutorunSpy).toHaveBeenCalled();
    });

    it('Should use the Meteor subscribe function when using it', function() {
      var mockedResult = {
        ready : jasmine.createSpy('ready'),
        stop : jasmine.createSpy('stop'),
        subscriptionId : '123'
      };
      var meteorSubscribeSpy = spyOn(Meteor, 'subscribe').and.returnValue(mockedResult);
      testScope.subscribe('', function() { return [] });

      expect(meteorSubscribeSpy).toHaveBeenCalled();
    });

    it('Should stop the subscription when calling stop on the return value', function() {
      var mockedResult = {
        ready : jasmine.createSpy('ready'),
        stop : jasmine.createSpy('stop'),
        subscriptionId : '123'
      };
      spyOn(Meteor, 'subscribe').and.returnValue(mockedResult);
      var oldAutorun = Meteor.autorun;
      Meteor.autorun = function(cb) {
        cb();
        return {stop: function() {mockedResult.stop()}};
      };
      var result = testScope.subscribe('', () => []);
      Meteor.autorun = oldAutorun;

      result.stop();
      result.ready();

      expect(mockedResult.stop).toHaveBeenCalled();
{'fraction_non_alphanumeric': 0.1254550546065528, 'fraction_numerical': 0.0022402688322598714, 'mean_word_length': 3.374157991426822, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5531537', 'n_tokens_mistral': 2100, 'n_tokens_neox': 2009, 'n_words': 376}