mockbot-element
mock html dom element
Installation
$ npm init
$ npm install mockbot-element --save-dev
Usage
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({});
el.setAttribute(testAttr,testValue);
var result = el.getAttribute(testAttr);
Modules
- mockbot-element
-
Module
- mockbot-element-factory
-
Factory module
mockbot-element
Module
Properties
| Name | Type | Description |
|---|---|---|
| id | String |
the id of the element |
| tagName | String |
read-only tagName of element as uppercase (i.e. 'DIV') |
mockbot-element.setAttribute(name, value)
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");mockbot-element.getAttribute(name)
mock element.getAttribute
Kind: instance method of mockbot-element
| Param | Type | Description |
|---|---|---|
| name | string |
attribute name |
Example (usage)
var w = el.getAttribute("width");
mockbot-element.cloneNode(deep) ⇒ mockbot-element
mock element.cloneNode
Kind: instance method of mockbot-element
| Param | Type | Description |
|---|---|---|
| deep | boolean |
If true, clone children as well |
Example (usage)
var n = el.cloneNode();mockbot-element-factory
Factory module
mockbot-element-factory.create(options) ⇒ mockbot-element
Factory method It takes one spec parameter that must be an object with named parameters
Kind: static method of mockbot-element-factory
| Param | Type | Description |
|---|---|---|
| options | Object |
Named parameters object |
Example (Usage example)
var factory = require("mockbot-element");
var obj = factory.create({});Testing
To test, go to the root folder and type (sans $):
$ npm test
Repo(s)
Contributing
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.
Version History
Version 0.1.5
- fixed documentation for getAttribute
Version 0.1.4
- added tagName property
Version 0.1.3
- added id property
- cleaned up documentation
- updated methods to simulate real methods
Version 0.1.2
- removed gitlab from package.json list
Version 0.1.1
- changed license to MIT
- integrated travis-ci and codecov.io
Version 0.1.0
- initial release