簡體   English   中英

對象# <Object> 沒有方法“類型”

[英]Object #<Object> has no method 'type'

我的測試代碼是

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)

但是type方法在documentation中指定。如何擺脫此錯誤。請提供幫助。

而不是當我嘗試運行時

a

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文檔#類型

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM