2016-04-15 52 views
2

在:jsdom虛擬控制檯:類型錯誤:jsdom.createVirtualConsole不是一個函數

const jsdom = require("jsdom"); 
const initialVirtualConsole = jsdom.createVirtualConsole(); 

我得到:

TypeError: jsdom.createVirtualConsole is not a function 
    at Query.<anonymous> (/my_jsdom_script.js:112:55) 
    at emitNone (events.js:72:20) 
    at Query.emit (events.js:166:7) 
    at Query.Sequence.end (/Users/xxx/Sites/node_modules/mysql/lib/protocol/sequences/Sequence.js:99:12) 
    at Query._handleFinalResultPacket (/Users/xxx/Sites/node_modules/mysql/lib/protocol/sequences/Query.js:144:8) 
    at Query.EofPacket (/Users/xxx/Sites/node_modules/mysql/lib/protocol/sequences/Query.js:128:8) 
    at Protocol._parsePacket (/Users/xxx/Sites/node_modules/mysql/lib/protocol/Protocol.js:280:23) 
    at Parser.write (/Users/xxx/Sites/node_modules/mysql/lib/protocol/Parser.js:73:12) 
    at Protocol.write (/Users/xxx/Sites/node_modules/mysql/lib/protocol/Protocol.js:39:16) 
    at Socket.<anonymous> (/Users/xxx/Sites/node_modules/mysql/lib/Connection.js:96:28) 
    at emitOne (events.js:77:13) 
    at Socket.emit (events.js:169:7) 
    at readableAddChunk (_stream_readable.js:146:16) 
    at Socket.Readable.push (_stream_readable.js:110:10) 
    at TCP.onread (net.js:523:20) 

我想我的本地機器上運行jsdom的測試,看看jsdom如何在我的本地環境中執行。

任何人都可以如此優秀地指導一個noob在https://github.com/tmpvar/jsdom/tree/master/test運行測試?

+0

你使用的jsdom的版本? –

+0

jsdom/tree/master ...所以一個移動的目標。 – baychae

回答

1

這裏是我的beforeEach()塊(我使用過的摩卡Node.js的測試)

import jsdom from 'jsdom' 
    const virtualConsole = jsdom.createVirtualConsole() 
    const document = jsdom.jsdom(undefined, { 
     virtualConsole: virtualConsole.sendTo(console) 
    }) 
    virtualConsole.on('log', (...args) => { 
     // do something with `args` sent to logs 
     // e.g, assign result to a variable and run your assertions over it 
    }) 
    window = document.defaultView 
    global.window = window 
    global.document = document 

退房測試什麼是更多的例子:https://github.com/tmpvar/jsdom/blob/master/test/jsdom/virtual-console.js

相關問題