对象#< Object>没有方法“类型" [英] Object #<Object> has no method 'type'

查看:59
本文介绍了对象#< Object>没有方法“类型"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的测试代码是

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');
  });

});

当我运行此测试时,它给我错误

and when i run this test.it is giving me error

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)

但是类型方法是在文档中指定的.如何消除此错误.请提供一些帮助.

but the type method is specified in documentation.how to get rid of this error.please help a bit.

当我尝试运行时代替

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)

推荐答案

should.js具有以下语法:

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

Should.js文档#类型

这篇关于对象#&lt; Object&gt;没有方法“类型"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆