jsdom

Testing A Library That Uses The Web Audio API With Mocha & Chai

≡放荡痞女 提交于 2019-12-11 17:42:07
问题 I am building a library which uses the web audio api(ToneJS to be more specific). I have tried using jsdom, mocha-jsdom with no success. I get this error - node_modules/tone/build/Tone.js:3869 this.input = this.output = this._gainNode = this.context.createGain(); Which makes sense and tells me that i need to use an environment with a context. I'm not even sure how i should setup the tests for my project. How should i setup a test environment correctly for my project? 回答1: I would suggest to

jsdom can't load local html and javascript

房东的猫 提交于 2019-12-11 16:32:07
问题 Thanks for any help. Using jsdom, I'm trying to load a local HTML file, which itself loads a local JS file. import jsdom from 'jsdom-no-contextify' var fs = require('fs'); var path = require("path"); var html = fs.readFileSync(path.join(__dirname, '../src/', 'launcher.html')); global.document = jsdom.jsdom(html, { FetchExternalResources: ['script'], ProcessExternalResources: ['script'], created: function (error, window) { console.log("created: " + error); }, url: "file://mydir/src/js

Chinese character in nodejs response write

放肆的年华 提交于 2019-12-11 08:38:56
问题 I cannot display chinese character response to browser using nodejs ? jsdom.env({ html: 'http://www.baidu.com', scripts: ['http://code.jquery.com/jquery-1.6.min.js'] }, function (err, window) { //Use jQuery just as in a regular HTML page var $ = window.jQuery; res.writeHead(200, { "Content-Type": "text/html; charset=utf-8" }); res.end($('title').text()); }); Incorrect result : �ٶ�һ�£�����֪�� Correct result should be : 百度一下,你就知道 回答1: 因为百度的网页编码是GBK的 because the charset of baidu.com is GBK 来源:

Why does my test finish before my (enzyme simulated event) synchronous event handler?

我怕爱的太早我们不能终老 提交于 2019-12-11 08:12:17
问题 I have a mocha based test which finishes before my onChange handler in a jsdom based enzyme test of my React component, despite that handler being synchronous using babel+ES2017. If I do a setTimeout() of 1ms to put my expect() calls in; the test passes . Just wondering where the break down is? I'm sure there is some simple concept here I'm not considering. I'm thinking jsdom or enzyme does not wait around for the event handler to finish? A problem compounded by the length of time mocking

Unable to install jquery with node.js - Unable to load Contextify

本小妞迷上赌 提交于 2019-12-11 07:38:13
问题 Update - see bottom of post I'm trying to setup jquery in node.js and having some trouble. As described on SO I'm installing jquery with npm install jquery and am executing my javascript as a script from the command line, rather than running it as a server. A few points to note: OS X 10.7.3 node.js version 0.6.11 npm version 1.1.1 node-waf version 1.5.16 So, from the directory that contains my node script, I npm install jquery . Terminal then goes off for 5 seconds and does a few things,

fetch doesn't work in jest, and return TypeError: Network request failed

送分小仙女□ 提交于 2019-12-11 02:29:27
问题 I am trying to migrate from karma + PhantomJS to Jest + jsDom, but I got a problem. all fetch in UT failed in Jest. I am trying to figure out the reason. So I just write a simple UT like this import fetch from 'isomorphic-fetch'; import $ from 'jquery'; describe('test', () => { it('should fetch success....', (done) => { return fetch('http://www.ebay.com/', { method: 'get' }) .then((res) => { console.log(res); done(); }) .catch(err => console.log(err)); }) it('should get success....', (done) =

Cross-compile Node.js contextify for ARM

风格不统一 提交于 2019-12-11 02:28:58
问题 I'm trying to cross-compile the node.js module contextify (as part of jsdom ) for ARM platform on my 64bit Fedora installation. However, I seem unable to build for any other platform than the one I'm running on. I've tried different ways such as running node-gyp --arch=arm configure rebuild , or also node-gyp configure --without-snapshot --dest-cpu=arm --dest-os=linux --with-arm-float-abi=softfp rebuild (a command I've found online somewhere when looking for this problem). The build runs

jsdom.env: local jquery script doesn't work

…衆ロ難τιáo~ 提交于 2019-12-11 01:36:41
问题 jsdom.env({ html: "<html><body></body></html>", scripts: [ //'http://code.jquery.com/jquery-1.5.min.js' 'http://server.local:3000/jquery/jquery.min.js' ] }, function (err, window) { it does not work script is 'http://server.local:3000/jquery/jquery.min.js' (its available using browser) jquery.min.js is a copy of jquery-1.5.min.js if script is 'http://code.jquery.com/jquery-1.5.min.js' - it all works. What is wrong? 回答1: It is not directly an answer to your question, but maybe others come to

React + Enzyme error: Invariant Violation: dangerouslyRenderMarkup(…): Cannot render markup in a worker thread

巧了我就是萌 提交于 2019-12-10 22:31:21
问题 I am testing a react component using Enzyme and I'm getting the following error: Invariant Violation: dangerouslyRenderMarkup(...): Cannot render markup in a worker thread. Make sure window and document are available globally before requiring React when unit testing or use ReactDOMServer.renderToString for server rendering I added the following setup for jsdom, before requiring 'enzyme' (as I read in few places): const baseMarkup = '<!DOCTYPE html><html><head><title></title></head><body><

jsdom and $(document).ready

断了今生、忘了曾经 提交于 2019-12-10 09:44:25
问题 I looks like when I run a page through jsdom , the $(document).ready block in the page script isn't being executed. Here is the html: <html> <body> If everything works, you should see a message here: <h2 id="msg"></h2> <script> var checkpoint1 = true var checkpoint2 = false $(document).ready(function(){ checkpoint2 = true $('#msg').html("It works, it works, it works!") }) </script> </body> </html> and the codez: fs = require('fs'); htmlSource = fs.readFileSync("public/examples/test_js_dom