Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when epxect failed throw err TypeError: undefined is not a function #278

Closed
stormslowly opened this issue Jul 5, 2014 · 1 comment
Closed

Comments

@stormslowly
Copy link

product.js

var express = require('express') // express 4.2.0
var router = express.Router();
router.get('/:uuid/:item', function (req, res) {
  res.end(300);
});
module.exports = router;

testcode.js

'use strict';
var expect = require('chai').expect;
var table = require('./product.js');

describe('table', function () {

  it('should pass ', function (done) {

    expect(1).to.equal(1);
    table.handle( { url: '/test/pois',method:'GET'},
      {
        end: function(statusCode){

          expect(statusCode).to.equal(200);

          done();
        }
      }
    );
  });
});

the case should failed , i expect chai.expect tell me that 200 is not equals to 300.
but it throws error like bellow. ( then i change it to expect(statusCode).to.equal(300); verything is ok)

1) table should pass :
     TypeError: undefined is not a function
      at D:\git\Qbengo\sliteSerivce\node_modules\express\lib\router\index.js:137:5
      at D:\git\Qbengo\sliteSerivce\node_modules\express\lib\router\index.js:250:10
      at next (D:\git\Qbengo\sliteSerivce\node_modules\express\lib\router\index.js:160:14)
      at next (D:\git\Qbengo\sliteSerivce\node_modules\express\lib\router\index.js:212:7)
      at Function.proto.handle (D:\git\Qbengo\sliteSerivce\node_modules\express\lib\router\index.js:151:3)
      at Context.<anonymous> (D:\git\Qbengo\sliteSerivce\test.js:11:11)
      at Test.Runnable.run (D:\userdata\pshu\Application Data\npm\node_modules\mocha\lib\runnable.js:204:15)
      at Runner.runTest (D:\userdata\pshu\Application Data\npm\node_modules\mocha\lib\runner.js:378:10)
      at D:\userdata\pshu\Application Data\npm\node_modules\mocha\lib\runner.js:456:12
      at next (D:\userdata\pshu\Application Data\npm\node_modules\mocha\lib\runner.js:303:14)
      at D:\userdata\pshu\Application Data\npm\node_modules\mocha\lib\runner.js:313:7
      at next (D:\userdata\pshu\Application Data\npm\node_modules\mocha\lib\runner.js:251:23)
      at Object._onImmediate (D:\userdata\pshu\Application Data\npm\node_modules\mocha\lib\runner.js:280:5)
      at processImmediate [as _immediateCallback] (timers.js:330:15)
@stormslowly
Copy link
Author

when expect failed, it throw errors. but there is no error handling in res.end.
so the end stub should not throw any error out.

'use strict';
var expect = require('chai')
  .expect;
var table = require('./product.js');


var expectStatus = function (expectCode, done) {

  return function (statusCode) {

    console.log('fsfsfsdfsfsfssd',expectCode,statusCode);
    try {
      expect(statusCode).to.equal(expectCode);
      done();
    } catch (e) {

      done(e);
      // console.log(e);
    }
  };
};


describe('table', function () {

  it('should pass ', function (done) {

    expect(1).to.equal(1);
    table.handle({
      url: '/test/pois',
      method: 'GET'}, {end: expectStatus(200, done)});
  });
});

i think is a solution for my problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant