How to mock DOM object in Js? [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I would like to add some unit tests to test UI of some javascript. However I don't want to use HTML page, I would like to use node.js.
Is there any js library which I can use to mock HTML DOM, like document?

Yes, You can use jsdom for this. It is what facebook's jest framework uses behind the scenes to run tests on components that use DOM via node.

You could consider using a headless browser. Depending on your technology stack there are multiple options. When using node.js A popular one is phantom.js. There're different test runners for different test frameworks, here's an overview of them.
mocha.js is a popular testing framework which has a phantom.js test runner.
If you're using browserify there's also mochify which works really nice.
There's also jsdom but one caveat with that one is that it only works with io.js from v4.0.0.

Related

Is ES6 a good choice over ES5 to develop a desktop(electron) app? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
I am developing a data science app that uses codes from python, R in the backend and for the frontend, I am using HTML, CSS, and js. By using electron framework I would like to make it into a desktop application. The role of js mainly, to read the files generated by R/python codes and produce interactive d3 plots. Speed is also one of my concern, I was wondering should I use ES6 or ES5? I have read that ES6 code gets transpiled into ES5 so that Node can run it natively. Does it mean that even if ES6 is used to develop the app, it will still run at the speed of ES5?
Thanks
Your code won't be transpiled by Electron, you'd have to do that yourself. So feel free to use the latest features of ES6 without worrying about performance issues.
According to the official website, Electron runs v12.14.1 of Node. You can see here that Node supports most ES6 features.

jQuery Plugin TDD Starting Point [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I have some existing Javascript code that I'm looking to port to a jQuery plugin. The code itself is nothing complex: Flickr API photo gallery with varying photo sizes, a few other things. I coded it up quickly and it's stable enough, but I want to redo it the "right way".
I set up a simple TDD environment based off Yeoman, with Grunt and Mocha, and it works well. The problem I have is that my plugin will work like most jQuery plugins, having a simple entry point:
$( '#ele' ).myAwesomePlugin( { ... } ); // Do all the things
and I'm scratching my head at where to start writing tests. While I already have most of the code to complete the plugin, I'm trying to go through the motions of the development being driven by the tests, and I don't know how to transition from this high-level point into the smaller portions of the code.
Some stages of the program flow would be: communicate with Flickr, gather photos (or not), divide them up into various sizes, and arrange them into a container.
The plugin itself would (ideally) only have one publicly-accessible method, but, if that's the case, how should my tests hook into my deeper logic? Should I be splitting my code up into smaller, testable chunks that aren't jQuery plugins, and then combine them? I'm curious if there's a way for tests themselves to drive that development.
Any recommendations on reading material or articles would be very helpful. I'm pretty excited finally to be doing TDD!
Here is a link to test-driven-development of jquery plugins with Jasmine.
BDD Testing of jQuery plugins using Jasmine
Jasmine is similar to Mocha, so you could follow the tutorial with either Jasmine or Mocha.

Looking for a Javascript unit testing framework [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
Improve this question
What do you recommend as the best and most documented Unit Test Framework for Javascript?
Jasmine is a BDD testing framework for javascript that works client-side or server-side. It works well in Rails, Node, Maven, etc. There's also a lot of plugins for things like jQuery.
Jquery team is using its Qunit for client side testing . It has a potential.
Check out this post. JSUnit is probably very effective, but I've found that Firebug now has an extension called FireUnit.
JSUnit is fairly useful, though it's been discontinued.
There are a whole bunch of modules found on the npm if you search for "unit test".
There is also the CommonJS testing specification.
I've written implementations of them which are on github. But I wouldn't call them production ready. There reasonably stable.
Very young, but still nicely functioning framework - bob.js.

Alternatives to libxmljs [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 2 years ago.
Improve this question
Goal: Use Node.js to access a web page, manipulate the DOM using xpath syntax, and print the new DOM.
libxmljs is okay, but it has several dependencies which NPM doesn't resolve. Which libraries do you use to xpath arbitrary HTML?
I develop libxmljs on Mac OS X, so this shouldn't be your major hurdle. You need the libxml2 library and the scons utility in order to build successfully. Both of these are available via macports or homebrew. Once you have libxml2, make sure the xml2-config command-line utility is in your path. That's what I use to get the appropriate build flags.
#mcandre I believe you're the same person who submitted a ticket to the github repo. I hope you've gotten things worked out. If not, give more info about your problem. https://github.com/polotek/libxmljs
:Marco

Browserless, ant-task-oriented Javascript Unit Testing? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 7 years ago.
Improve this question
I'm looking for a javascript unit test framework that I can use as part of my automated maven build. This CANNOT use an actual browser, and it MUST be fully browserless.
I've tried looking at a few posts on SO, but none seem to meet my needs. Is there such a javascript unit tester? I'm anxious to find out.
I was trying to solve the same problem. It seems, that this is not as common, as one might think from our perspective.
RhinoUnit looks very good.
If you need browser capabilities within Rhino, take a look at
http://ejohn.org/blog/bringing-the-browser-to-the-server/
http://groups.google.com/group/envjs
http://github.com/thatcher/env-js/tree/master
There are two projects called JSUnit (www.jsunit.net) and (jsunit.berlios.de). The latter is designed to work with Rhino and Maven. Note that there will be browser-specific problems that such tests will not discover, but it should help with basic functionality.
Not sure about a JavaScript unit testing framework, though I'm sure there is one. But I would probably look towards Rhino as JS interpreter.
http://www.mozilla.org/rhino/
If your JS references any of the browser/DOM you'll also need to mock/stub those...
Have you tried JSunit?
AFAIK, javascript is a language specifically designed to run in the browser.
Have you considereds j-unit tests? They do still run in the browser however.

Categories

Resources