it('should invoke http service detach', function() {
            var route = this.context.from('http-inbound:http://0.0.0.0')
                .to(function() {
                    console.log('888888888888');
                });

            var c = route.query('http-inbound:http://0.0.0.0');

            this.$http.detach = chai.spy();

            this.context.stop();

            expect(this.$http.detach).to.be.called();
        });
      it('Is called after the manifest is set up', function() {
        const mock = chai.spy();
        const manifest = new WebpackAssetsManifest({
          apply() {
            mock();
          },
        });

        expect( mock ).to.not.have.been.called();

        manifest.apply( makeCompiler( configs.hello() ) );

        expect( mock ).to.have.been.called();
      });
    it('should read out invalid messages and send it to errors queue', (done) => {
      consumer.isFailedMessage = chai.spy(() => {
        return true
      });

      consumer.handleMessage().then(() => {
        expect(redisClient.retrieveMessage).to.be.called();
        expect(redisClient.sendErrorMessage).to.be.called();
        done();

      }).catch((error) => {
        done(error)
      });
    });
    it('should not trigger an update event if a duplicate entry is added', () => {
        const spy = chai.spy();
        const config = { updateEventName: EVENT_NAME };
        const blacklistController = BlacklistController(context).create(config);

        eventBus.on(EVENT_NAME, spy);

        blacklistController.add(SERVICE_LOCATION);
        blacklistController.add(SERVICE_LOCATION);

        expect(spy).to.have.been.called.once; // jshint ignore:line

        eventBus.off(EVENT_NAME, spy);
    });
Esempio n. 5
0
    it('should emit on document insert', function (done) {
        function onstream(args) {
            expect(args.name).to.be.equal('$inge');
            expect(args.data).to.be.deep.equal({dress: '$noir', '_version': 0});
        }
        var spy = chai.spy(onstream);
        model.on('stream', spy);

        model.insert(new Document({name: '$inge', data: {dress: '$noir'}}));
        setTimeout(function () {
            expect(spy).to.have.been.called.once;
            done();
        }, 500);
    });
Esempio n. 6
0
    describe('click',function(){
        var onclickListener = chai.spy();
        
        it('should add listener',function(){
            on('click',onclickListener);
            expect(element.events.click[0]).to.be.instanceof(Function);
        });
        
        it('should be called',function(){
            element.fire('click');
            expect(onclickListener).to.have.been.called.once;
        });

    });
Esempio n. 7
0
 it('should pass only when called with the arguments the second time', function() {
   var spy = chai.spy();
   spy(1, 2, 3)
   spy(3, 4, 5)
   spy.should.have.been.second.called.with(3, 4, 5)
   spy.should.have.been.second.called.with(4, 5);
   spy.should.not.have.been.second.called.with(1);
   (function () {
     spy.should.have.been.second.called.with(3, 4, 1)
   }).should.throw(chai.AssertionError, /have been called at the second time with/);
   (function () {
     spy.should.have.not.been.second.called.with(4, 5);
   }).should.throw(chai.AssertionError, /have not been called at the second time with/);
 });
Esempio n. 8
0
  describe('setup', function () {
    let spy = chai.spy();
    beforeEach(function () {
      noun._afterSetup(spy);
    });

    beforeEach(function () {
      noun.setup();
    });

    it('calls the after setup functions', function () {
      expect(spy).to.have.been.called();
    });
  });
Esempio n. 9
0
    it('should make explosion after 3000 ms after instancing', function () {
        clock = sinon.useFakeTimers();

        var bomb = new Bomb();
        bomb.bang = chai.spy(new Function());

        clock.tick(2999);
        expect(bomb.bang).to.have.not.called();

        clock.tick(1);
        expect(bomb.bang).to.have.been.once.called();

        clock.restore();
    });
Esempio n. 10
0
 it('Should work with the shorthand second for nth(2)', function() {
   var spy = chai.spy();
   spy(1, 2, 3);
   spy(3, 4, 5);
   spy.should.have.been.second.called.with.exactly(3, 4, 5);
   spy.should.have.been.not.second.called.with.exactly(1, 2, 3);
   spy.should.have.been.not.second.called.with.exactly(4);
   (function() {
     spy.should.have.been.second.called.with.exactly(4, 5)
   }).should.throw(chai.AssertionError);
   (function() {
     spy.should.have.not.been.second.called.with.exactly(3, 4, 5)
   }).should.throw(chai.AssertionError);
 });
Esempio n. 11
0
    it('should set a cookie with the session csrfSecret', function() {
      var token = 'token';
      request = {
        csrfToken: function() {
          return token;
        }
      };
      response = chai.spy.object(['cookie']);
      next = chai.spy();

      loginUtils.setXSRFTokenMiddleware(request, response, next);
      expect(response.cookie).to.have.been.called.with('XSRF-TOKEN', token);
      expect(next).to.have.been.called();
    });
describe('SplitPane can have resizing callbacks', function () {
    const onDragStartedCallback = chai.spy(function() { });
    const onDragFinishedCallback = chai.spy(function() { });

    const splitPane = (
        <SplitPane className="some-class"
          onDragStarted = { onDragStartedCallback }
          onDragFinished = { onDragFinishedCallback }
        >
            <div>one</div>
            <div>two</div>
        </SplitPane>
    );


    it('should call callbacks on resizing', function () {
        asserter(splitPane).assertResizeCallbacks(
          onDragStartedCallback,
          onDragFinishedCallback
        );
    });

});
    it('should not call MANIFEST_UPDATED if a parsing error occurs, errorHandler should send an error', function () {
        const spy = chai.spy();
        eventBus.on(Events.MANIFEST_UPDATED, spy);

        eventBus.trigger(Events.INTERNAL_MANIFEST_LOADED, {
            error: {code: Errors.MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE, message: manifestErrorMockText}
        });

        expect(spy).to.have.not.been.called(); // jshint ignore:line

        eventBus.off(Events.MANIFEST_UPDATED, spy);

        expect(errHandlerMock.errorCode).to.equal(Errors.MANIFEST_LOADER_PARSING_FAILURE_ERROR_CODE); // jshint ignore:line
    });
Esempio n. 14
0
  it('should error if a conflicting alias is attempted to be registered', function () {
    var errSpy = regexSpy('Attempted to register');
    var resSpy = chai.spy();

    // We should get success the first time...
    var alias = {name: 'foo', route: 'bar'};
    this.rito.registerRoute(alias, errSpy, resSpy);

    // And an error the second time.
    alias.route = 'baz';
    this.rito.registerRoute(alias, errSpy, resSpy);

    errSpy.should.have.been.called.once();
    resSpy.should.have.been.called.once();
  });
  it('should render stuff', () => {
    const props = {
      currentCountry: 'BE',
      onPress: chai.spy(),
    };

    const wrapper = shallow(<CountryButton {...props} />);
    const item = wrapper.findWhere((component) => {
      return component.props().children === 'BE';
    });
    expect(item.length).to.equal(1);

    wrapper.find(TouchableHighlight).simulate('press');
    return expect(props.onPress).to.have.been.called.once;
  });
    it('should add an historic to the manageable\'s history', function(done) {
      expectedManageables = [
        {
          id: '42',
          history: []
        }
      ];
      var expectedHistoric = {id: '43'};

      EntityProvider.prototype.getOne = chai.spy(function(filter, fields, callback) {
        assert.equal(
          filter.getComparisonOperation(ResourceFilter.OPERATORS.EQUAL, 'id').value,
          expectedManageables[0].id,
          'Wrong id'
        );
        callback(null, expectedManageables[0]);
      });

      EntityProvider.prototype.updateOne = chai.spy(function(filter, modifications, callback) {
        assert.equal(
          filter.getComparisonOperation(ResourceFilter.OPERATORS.EQUAL, 'id').value,
          expectedManageables[0].id,
          'Wrong id'
        );
        assert.strictEqual(modifications.history[0], expectedHistoric, 'Wrong historic');
        callback(null, 1);
      });

      provider.addHistoric(expectedManageables[0].id, expectedHistoric, function(error, total) {
        assert.isNull(error, 'Unexpected error');
        assert.equal(total, 1, 'Wrong total');
        EntityProvider.prototype.getOne.should.have.been.called.exactly(1);
        EntityProvider.prototype.updateOne.should.have.been.called.exactly(1);
        done();
      });
    });
    it('should add a new schedule', function(done) {
      expectedManageables = [
        {
          id: '42',
          schedules: []
        }
      ];
      var expectedSchedule = {id: '43'};

      EntityProvider.prototype.getOne = chai.spy(function(filter, fields, callback) {
        assert.equal(
          filter.getComparisonOperation(ResourceFilter.OPERATORS.EQUAL, 'id').value,
          expectedManageables[0].id,
          'Wrong id'
        );
        callback(null, expectedManageables[0]);
      });

      EntityProvider.prototype.updateOne = chai.spy(function(filter, data, callback) {
        assert.equal(
          filter.getComparisonOperation(ResourceFilter.OPERATORS.EQUAL, 'id').value,
          expectedManageables[0].id,
          'Wrong id'
        );
        assert.strictEqual(data.schedules[0], expectedSchedule, 'Wrong schedule');
        callback(null, 1);
      });

      provider.addSchedule(expectedManageables[0].id, expectedSchedule, function(error, total) {
        assert.isNull(error, 'Unexpected error');
        assert.equal(total, 1, 'Wrong total');
        EntityProvider.prototype.getOne.should.have.been.called.exactly(1);
        EntityProvider.prototype.updateOne.should.have.been.called.exactly(1);
        done();
      });
    });
    it('should remove an historic from the manageable\'s history', function(done) {
      var expectedHistoric = {id: '43'};
      expectedManageables = [
        {
          id: '42',
          history: [expectedHistoric]
        }
      ];

      EntityProvider.prototype.getOne = chai.spy(function(filter, fields, callback) {
        assert.equal(
          filter.getComparisonOperation(ResourceFilter.OPERATORS.EQUAL, 'id').value,
          expectedManageables[0].id,
          'Wrong id'
        );
        callback(null, expectedManageables[0]);
      });

      EntityProvider.prototype.updateOne = chai.spy(function(filter, data, callback) {
        assert.equal(
          filter.getComparisonOperation(ResourceFilter.OPERATORS.EQUAL, 'id').value,
          expectedManageables[0].id,
          'Wrong id'
        );
        assert.equal(data.history.length, 0, 'Wrong history');
        callback(null, 1);
      });

      provider.removeHistoric(expectedManageables[0].id, expectedHistoric.id, function(error, total) {
        assert.isNull(error, 'Unexpected error');
        assert.equal(total, 1, 'Wrong total');
        EntityProvider.prototype.getOne.should.have.been.called.exactly(1);
        EntityProvider.prototype.updateOne.should.have.been.called.exactly(1);
        done();
      });
    });
 it('it calls ensureScriptHasLoaded and updateTinypass', (done) => {
   window.tp = {
     setCustomVariable: () => null,
     setPageURL: () => null,
     push: () => null,
   };
   const plugin = new ReactI13nPiano({ ...PianoConfig });
   plugin.ensureScriptHasLoaded = chai.spy(() => Promise.resolve());
   const payload = {
     example: 'test',
   };
   plugin.updateTinypass = chai.spy();
   plugin.generatePayload = chai.spy();
   plugin.customEvent(payload, 'pageview').then(() => {
     plugin.ensureScriptHasLoaded.should.have.been.called.exactly(1);
     plugin.updateTinypass.should.have.been.called.exactly(1);
     plugin.generatePayload.should.have.been.called.exactly(1);
     plugin.generatePayload.should.have.been.called.with(payload, 'pageview');
     done();
   })
   .catch((error) => {
     done(error);
   });
 });
    it('notifies if it is successful', (done) => {
      const props = {
        notify: chai.spy(noop),
        cancelSubscription: noop,
        token: 'token_abc'
      };

      window.confirm = () => true;

      cancel.call({props})
        .then(() => {
          expect(props.notify).to.have.been.called.with('success');
          done();
        });
    });
Esempio n. 21
0
    it('can cancel a job by job model', function (done) {
      var spy = chai.spy(function (job) {
        job.should.deep.equal(job1);
      });

      task1.on('cancelled', spy);
      job1.get('status').should.equal('queued');
      queue.cancel(job1, function (err) {
        should.not.exist(err);
        job1.get('status').should.equal('cancelled');
        spy.should.have.been.called.once;
        task1.off('cancelled', spy);
        done();
      });
    });
	it('should use a global token cache', function (done) {

		var tokens = moduleToTest.TokenCache.global;
		tokens.get = chai.spy(tokens.get);
		tokens.authenticate = chai.spy(tokens.authenticate);

		// clear the global cache in case it has been used by other tests
		tokens.clear();
		expect(_.keys(tokens._cache)).to.have.length(0);

		function requestWithoutTokenCache(next) {
			// use a new instance each time
			var request = moduleToTest.requestWithJWT();
			request({
				url: jwt_settings.test_url,
				jwt: jwtSettings()
			}, function (err, res, body) {
				expect(res.statusCode).to.equal(200);
				next(err);
			});
		}

		// perform 3 simultaneous requests with 3 separate instances - the same cache should be used
		async.parallel([
			requestWithoutTokenCache,
			requestWithoutTokenCache,
			requestWithoutTokenCache
		], function (err) {
			if (err) throw er
			expect(_.keys(tokens._cache)).to.have.length(1);
			expect(tokens.get).to.have.been.called.exactly(3);
			expect(tokens.authenticate).to.have.been.called.once;
			done();
		});

	});
		it('should issue only one request on concurrent calls', function (done) {

			var tokens = new moduleToTest.TokenCache();
			tokens.authenticate = chai.spy(fakeAuth);
			tokens.get = chai.spy(tokens.get);

			// make 5 simultaneous calls on an empty cache - only one should make the request
			async.parallel([
				function (next) { tokens.get(jwt_settings, next) },
				function (next) { tokens.get(jwt_settings, next) },
				function (next) { tokens.get(jwt_settings, next) },
				function (next) { tokens.get(jwt_settings, next) },
				function (next) { tokens.get(jwt_settings, next) }
			], function (err, results) {
				if (err) throw err;
				expect(tokens.authenticate).to.have.been.called.once;
				expect(tokens.get).to.have.been.called.exactly(5);
				results.forEach(function (token) {
					expect(token).to.equal('fake_token');
				});
				done();
			});

		});
Esempio n. 24
0
    it('should push all documents', function (done) {
        function onpush(args) {
            expect(args).to.have.property('$inge');
            expect(args['$inge']).to.be.deep.equal({'_version': 0, dress: '$noir'});
        }
        var spy = chai.spy(onpush);
        model.on('push', spy);
        model.insert(new Document({name: '$inge', data: {dress: '$noir'}}));
        model.emit('channel:' + model.channelname + ':all', ['REQ']);

        setTimeout(function () {
            expect(spy).to.have.been.called.once;
            done();
        }, 500);
    });
Esempio n. 25
0
 it('Should work with the shorthand third for nth(3)', function() {
   var spy = chai.spy();
   spy(1, 2, 3);
   spy(3, 4, 5);
   spy(5, 6, 7);
   spy.should.have.been.third.called.with.exactly(5, 6, 7);
   spy.should.have.been.not.third.called.with.exactly(5);
   spy.should.have.been.not.third.called.with.exactly(6, 5, 7);
   (function() {
     spy.should.have.been.third.called.with.exactly(7, 6, 5)
   }).should.throw(chai.AssertionError);
   (function() {
     spy.should.have.not.been.third.called.with.exactly(5, 6, 7)
   }).should.throw(chai.AssertionError);
 });
Esempio n. 26
0
    describe('if the user is not logged in', function() {

      var response = chai.spy.object(['json']);
      var request = {
        session: {}
      };
      var next = chai.spy();


      it('should return a 403 FORBIDDEN.', function() {
        loginUtils.emailHashMiddleware(request, response, next);
        expect(response.status).to.equal(status.FORBIDDEN);
        expect(next).to.have.been.called();
      });
    });
Esempio n. 27
0
 it('should know when a spy has been called at least n times', function () {
   var spy = chai.spy();
   spy();
   spy();
   spy.should.have.been.called.min(2);
   spy.should.have.been.called.at.least(1);
   (2).should.be.at.least(2);
   (2).should.be.at.least(1);
   (function () {
     spy.should.have.been.called.min(3);
   }).should.throw(chai.AssertionError);
   (function () {
     spy.should.not.have.been.called.above(1);
   }).should.throw(chai.AssertionError);
 });
Esempio n. 28
0
    it ('should emit an error on malformed JSON', function () {
      var file, stream, spy;
      stream = plugin('asdf');
      spy = chai.spy();
      stream.on('error', spy);

      file = new File({
        path: 'mock/path.json',
        contents: new Buffer('{a:b}')
      });
      expect(function () {
        stream.write(file);
      }).to.not.throw();
      expect(spy).to.have.been.called();
    });
Esempio n. 29
0
  it(`should listen to a node with .get`, () => {
    let source = getSource()
    let spy = chai.spy()

    source.get(`nested/location`).subscribe(spy)

    expect(on).to.be.called.once()
    expect(
      trimPath(on.__spy.calls[0][0])
    ).to.eql(`nested/location`)
    expect(on.__spy.calls[0][1]).to.eql(`value`)
    let callback = on.__spy.calls[0][2]
    callback({ val: () => `VALUE` })
    expect(spy).to.be.called.once.with(`VALUE`)
  })
    it('notifies if it fails', (done) => {
      const props = {
        notify: chai.spy(noop),
        cancelSubscription: () => Promise.reject({ message: 'canceling failed' }),
        token: 'token_abc'
      };

      window.confirm = () => true;

      cancel.call({props})
        .then(() => {
          expect(props.notify).to.have.been.called.with('error');
          done();
        });
    });