describe('if the user is logged in', function() {

      var next = chai.spy();
      var request = {
        session: {
          auth: {
            google: {
              user: {
                name: 'John Doe',
                email: '*****@*****.**'
              }
            }
          }
        }
      };
      var response = chai.spy.object(['json']);

      it('should place on the response an object with the md5 hashed email' +
        'of the google-logged-in user and call next',
        function() {
          loginUtils.emailHashMiddleware(request, response, next);
          expect(next).to.have.been.called();
          expect(response.json).to.have.been.called.with({
            name: request.session.auth.google.user.name,
            md5Hash: '6a6c19fea4a3676970167ce51f39e6ee'
          });
        });
    });
    it('does not log a deprecation warning', function() {
      var spy = chai.spy.on(console, 'warn');

      callbackOrPromise(function() {}, function() {});

      expect(spy).to.have.not.been.called;
    });
test('Set framework and call this.fountainPrompting', t => {
  context.fountainPrompting = () => {};
  const spy = chai.spy.on(context, 'fountainPrompting');
  TestUtils.call(context, 'prompting.fountain');
  t.is(context.options.framework, 'angular1');
  expect(spy).to.have.been.called.once();
});
示例#4
0
	it("should align because it's a correct request", async () => {
		module_mock.start_dictionary = async (env) => true;
		const rtm = chai.spy.object([ 'sendMessage' ]);   
		const res = await sut.handleEvent({message: {text: 'bot allinea dict/dev!'}, is_mention: true, rtm: rtm});
		
		assert.ok(res);
		chai.expect(rtm.sendMessage).to.have.been.called();
	});
      it('should do nothing if the queue is empty', () => {
        chai.spy.on(bleno, 'startAdvertisingIBeacon')
        beacon.advertising = false
        beacon.beaconQueue.length.should.equal(0)

        beacon.startAdvertisingNextBeacon()
        bleno.startAdvertisingIBeacon.should.not.have.been.called()
      })
      it('should do nothing if beacon is currently advertising', () => {
        chai.spy.on(bleno, 'startAdvertisingIBeacon')
        beacon.advertising = true
        beacon.beaconQueue.push(data1)

        beacon.startAdvertisingNextBeacon()
        bleno.startAdvertisingIBeacon.should.not.have.been.called()
      })
      it('uses `Array.isArray`', () => {
        const isArray = chai.spy.on(Array, 'isArray')
        const array = [1, 2, 3]

        forEach(array, () => {})

        expect(isArray).to.have.been.called
      })
示例#8
0
    it('should overwrite all methods with the same implementation', function () {
      chai.spy.on(object, ['push', 'pop'], function() {
        return 5;
      });

      object.push().should.equal(5);
      object.pop().should.equal(5);
    })
示例#9
0
test(`Call this.copyTemplate 2 times with 'dir' option`, t => {
  const spy = chai.spy.on(context, 'copyTemplate');
  TestUtils.call(context, 'writing', {dir: 'game'});
  expect(spy).to.have.been.called.exactly(2);
  t.true(1 + 1 === 2);
  // t.true(context.copyTemplate['src/app/game/directive.js'].length > 0);
  // t.true(context.copyTemplate['src/app/game/directive.spec.js'].length > 0);
});
    it('should redirect to signin if no user signed in on a secure url', function() {
      response = chai.spy.object(['sendStatus']);
      request.session = {};
      request.url = '/secure-me';
      next;

      loginUtils.securityMiddleware(request, response, next);
      expect(response.sendStatus).to.have.been.called.with(403);
    });
    it('counts down from n to 0', () => {
      const spy = chai.spy.on(console, 'log')
      const n = Math.floor(Math.random() * 100)

      expect(whileLoop(n)).to.equal('done')
      expect(spy).to.have.been.called.exactly(n)

      console.log.reset()
    })
示例#12
0
      it('should broadcast the racers registration', (done) => {
        let racerC = accounts[3]
        chai.spy.on(race, 'broadcastCommit')

        race.commitSelf({from: racerC, gas: MAX_GAS}).then(() => {
          race.broadcastCommit.should.have.been.called
          race.deleteLastRacer(racerC).then(del => done()) // Clean up
        })
      })
    it("logs that the item has been added", () => {
      chai.spy.on(console, 'log')

      addToCart('pizza')

      expect(console.log).to.have.been.called.with("pizza has been added to your cart.");

      console.log.reset()
    })
示例#14
0
    it('should return value from spied method', function () {
      var object = chai.spy.interface({
        push: function () {
          return 'push';
        }
      });

      object.push().should.equal('push');
    });
 it('should set a timeout to stop advertising beacon after specified interval', (done) => {
   chai.spy.on(bleno, 'stopAdvertising')
   beacon._units.onAdvertisingStart()
   bleno.stopAdvertising.should.not.have.been.called()
   setTimeout(() => {
     bleno.stopAdvertising.should.have.been.called()
     done()
   }, 110)
 })
示例#16
0
 beforeEach(function(){
     stateSpy = chai.spy(function(){
                 return stateProvider;
             });
     stateProvider = {
             state: stateSpy
         };
     urlRouteProvider = chai.spy.object(['otherwise']);
 });
    it("doesn't let you place an order if you don't provide a credit card number", () => {
      chai.spy.on(console, 'log');

      placeOrder();

      expect(console.log).to.have.been.called.with("We don't have a credit card on file for you to place your order.");

      console.log.reset()
    });
示例#18
0
test(`Call this.copyTemplate 20 times`, t => {
  const spy = chai.spy.on(context, 'copyTemplate');
  TestUtils.call(context, 'writing.src', {
    version: require('../../../package.json').version,
    date: new Date().toString()
  });
  expect(spy).to.have.been.called.exactly(files.length);
  files.forEach(file => t.true(context.copyTemplate[file].length > 0));
});
test(`Call 'this.option' 4 times with correct parameters`, () => {
  context.option = () => {};
  const spy = chai.spy.on(context, 'option');
  context.constructor();
  expect(spy).to.have.been.called.exactly(4);
  expect(spy).to.have.been.called.with('framework');
  expect(spy).to.have.been.called.with('modules');
  expect(spy).to.have.been.called.with('css');
  expect(spy).to.have.been.called.with('js');
});
    it('performs `callback` on `array` using `Array.prototype.forEach`', () => {
      const callback = chai.spy()
      const array = [1, 2, 3]
      const forEach = chai.spy.on(array, 'forEach')

      doToElementsInArray(array, callback)

      expect(callback).to.have.been.called
      expect(forEach).to.have.been.called
    })
示例#21
0
      it('should check to see if the caller came first', () => {
        let now = web3.eth.blockNumber
        chai.spy.on(race, 'isFirst')

        return Promise.all([
          race.setClientEndBlock(racerA, now, {from: node, gas: MAX_GAS}),
          race.setClientState(racerA, endState, {from: node, gas: MAX_GAS})
        ])
        .then( setup => race.rewardSelf({from: racerA, gas: MAX_GAS})
        .then( rewarded => race.isFirst.should.have.been.called))
      })
      it('should NOT set a timeout if there was an error', (done) => {
        let err = true
        chai.spy.on(bleno, 'stopAdvertising')
        beacon._units.onAdvertisingStart(err)

        bleno.stopAdvertising.should.not.have.been.called()
        setTimeout(() => {
          bleno.stopAdvertising.should.not.have.been.called()
          done()
        }, 110)
      })
    it('should print a ticket to the console log', () => {
      let printerSpy = chai.spy.on(console, 'log');

      consolePrinter.printTicket(ticket);
      let terminalTape = lastCallOf(printerSpy)
      expect(terminalTape).to.contain(ticket.watch);
      expect(terminalTape).to.contain(ticket.title);
      expect(terminalTape).to.contain(ticket.project);
      expect(terminalTape).to.contain(ticket.number);
      expect(terminalTape).to.contain(ticket.body);
    });
    it('invokes the passed-in callback function on every element of the passed-in array using Array.prototype.forEach()', () => {
      const callback = function(fruit) {
        return `Mmmm, ${fruit}!!!`;
      };

      const array = ["apple", "banana", "cherry"];
      const forEach = chai.spy.on(array, 'forEach');

      doToElementsInArray(array, callback);

      expect(forEach).to.have.been.called.with(callback);
    });
示例#25
0
    it('should wrap each method in spy', function () {
      var array = [];
      var object = chai.spy.interface({
        push: function() {
          return array.push.apply(array, arguments);
        }
      });

      object.push(1, 2, 3);

      object.push.should.be.a.spy;
      array.should.have.length(3);
    });
    it("should fail if just password is null", function() {
      var res = chai.spy.object(['negotiate']);
      var param = chai.spy(function(key) {
        if (key == 'username') return 'david';
        if (key == 'password') return null;
        return null;
      });
      var req = { param: param };

      UserController.signup(req, res);

      expect(res.negotiate).to.have.been.called.once;
    });
    it("lets you place an order with a credit card", () => {
      chai.spy.on(console, 'log');

      addToCart('pizza')

      const t = total()

      placeOrder(123);

      //expect(console.log).to.have.been.called.with(`Your total cost is $${t}, which will be charged to the card 123.`)

      console.log.reset()
    });
    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();
    });
    it("alerts you if you're trying to remove an item that isn't in your cart", () => {
      chai.spy.on(console, 'log');

      removeFromCart("sock")

      expect(console.log).
        to.
        have.
        been.
        called.
        with(
          "That item is not in your cart."
        );
    });
示例#30
0
		it("obj working", function(){

			expect(obj.test()).to.equal("working");
			var arr = ["","",""];
			var spy = chai.spy.on(obj, "test");
			console.log('arr', arr);
			var arr2 = arr.map(function () {
				return spy()
			});
			console.log('arr2', arr2);
			expect(spy).to.have.been.called(arr.length);
			expect(arr[1]).to.equal("");
			expect(arr2[1]).to.equal("working");
		})