
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mockbot-element
Advanced tools
$ npm init
$ npm install mockbot-element --save-dev
With tools like browserify, it's easy to create client side code in node.js. But, when testing with tools like mocha, code that references browser elements or the document object will throw an error.
This can be worked around by creating a mock object that simulates the browser object:
var elementFactory = require('mockbot-element');
var testAttr = "alpha",
testValue = "zorro",
el = elementFactory.create({ tagName: "div", id: "d1" });
el.setAttribute(testAttr,testValue);
var result = el.getAttribute(testAttr);
This package is also installed as part of mockbot-document. Through mockbot-document you can create mockbot-elements by simulating the browser document.createElement method.
This package derives from mockbot-node. See that packages documentation for additional methods.
mockbot-nodeModule
Factory module
MockBot Node
mockbot-nodeModule
Extends: mockbot-node
Properties
| Name | Type | Description |
|---|---|---|
| id | String | the id of the element |
| tagName | String | read-only tagName of element as uppercase (i.e. 'DIV') |
| outerHTML | String | WARNING: only get currently works, set not implemented |
mock element.setAttribute
Kind: instance method of mockbot-element
| Param | Type | Description |
|---|---|---|
| name | string | attribute name |
| value | string | attribute value |
Example (usage)
el.setAttribute("width","5");
mock element.getAttribute
Kind: instance method of mockbot-element
| Param | Type | Description |
|---|---|---|
| name | string | attribute name |
Example (usage)
var w = el.getAttribute("width");
return value of outerHTML
Kind: instance method of mockbot-element
Example (usage)
console.log("ELEMENT: " + el);
Factory module
mockbot-elementFactory method It takes one spec parameter that must be an object with named parameters
Kind: static method of mockbot-element-factory
| Param | Type | Description |
|---|---|---|
| spec | Object | Named parameters object |
| spec.tagName | string | required HTML tagName (a, div, x-thing, etc.) |
| spec.id | string | optional id attribute for HTML element |
Example (Usage)
var factory = require("mockbot-element");
var obj = factory.create({ tagName: "div" });
Example (Usage with id)
var factory = require("mockbot-element");
var obj = factory.create({ tagName: "div", id: "d1" });
MockBot Node
Kind: global external
See: mockbot-node
To test, go to the root folder and type (sans $):
$ npm test
In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.
FAQs
mock html dom element
We found that mockbot-element demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.