Object#<object>没有方法'type'</object>

时间:2013-10-10 18:18:32

标签: node.js npm mocha should.js

我的测试代码是

var strategy = require('../lib');
var should = require("should");
describe('passport-twitter', function() {

  it('should export Strategy constructor directly from package', function() {
    console.log('strategy is',strategy);
    strategy.should.have.type('function');
  });

  it('should export Strategy constructor', function() {
    strategy.Strategy.should.have.type('function');
  });

});

当我运行这个test.it给我错误

1) passport-twitter should export Strategy constructor directly from package:
     TypeError: Object #<Object> has no method 'type'
      at Context.<anonymous> (/home/ritesh/projects/passport-topcoder/test/module.test.js:7:26)
      at Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:211:32)
      at Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:358:10)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:404:12
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:284:14)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:293:7
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:237:23)
      at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:261:5)
      at processImmediate [as _immediateCallback] (timers.js:330:15)

  2) passport-twitter should export Strategy constructor:
     TypeError: Object #<Object> has no method 'type'
      at Context.<anonymous> (/home/ritesh/projects/passport-topcoder/test/module.test.js:11:35)
      at Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:211:32)
      at Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:358:10)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:404:12
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:284:14)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:293:7
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:237:23)
      at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:261:5)
      at processImmediate [as _immediateCallback] (timers.js:330:15)

但是在documentation.how中指定了type方法来摆脱这个错误。请稍微帮助。

当我尝试运行

时,

而不是这个

AA

var strategy = require('..');
var should = require("should");
describe('passport-twitter', function() {

  it('should export', function() {
    console.log('strategy is',strategy);
   'xxxx'.should.have.type('function');
  });

});

我仍然收到错误

 1) passport-twitter should export:
     TypeError: Object #<Object> has no method 'type'
      at Context.<anonymous> (/home/ritesh/projects/passport-topcoder/test/module.test.js:7:23)
      at Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:211:32)
      at Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:358:10)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:404:12
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:284:14)
      at /usr/local/lib/node_modules/mocha/lib/runner.js:293:7
      at next (/usr/local/lib/node_modules/mocha/lib/runner.js:237:23)
      at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:261:5)
      at processImmediate [as _immediateCallback] (timers.js:330:15)

1 个答案:

答案 0 :(得分:0)

should.js具有以下语法:

'xxxx'.should.be.type('string');

Should.js documentation # type