0.1.8 • Published 7 years ago

mockbot-element v0.1.8

Weekly downloads
12
License
MIT
Repository
github
Last release
7 years ago

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({ tagName: "div", id: "d1" });
    
el.setAttribute(testAttr,testValue);
var result = el.getAttribute(testAttr);

mockbot-document integration

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.

mockbot-node

This package derives from mockbot-node. See that packages documentation for additional methods.


Modules

External

mockbot-element ⇐ mockbot-node

Module

Extends: mockbot-node
Properties

NameTypeDescription
idStringthe id of the element
tagNameStringread-only tagName of element as uppercase (i.e. 'DIV')
outerHTMLStringWARNING: only get currently works, set not implemented

mockbot-element.setAttribute(name, value)

mock element.setAttribute

Kind: instance method of mockbot-element

ParamTypeDescription
namestringattribute name
valuestringattribute value

Example (usage)

el.setAttribute("width","5");

mockbot-element.getAttribute(name)

mock element.getAttribute

Kind: instance method of mockbot-element

ParamTypeDescription
namestringattribute name

Example (usage)

var w = el.getAttribute("width");

mockbot-element.toString()

return value of outerHTML

Kind: instance method of mockbot-element
Example (usage)

console.log("ELEMENT: " + el);

mockbot-element-factory

Factory module

mockbot-element-factory.create(spec) ⇒ mockbot-element

Factory method It takes one spec parameter that must be an object with named parameters

Kind: static method of mockbot-element-factory

ParamTypeDescription
specObjectNamed parameters object
spec.tagNamestringrequired HTML tagName (a, div, x-thing, etc.)
spec.idstringoptional 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

MockBot Node

Kind: global external
See: mockbot-node


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.8

  • moved node base method (cloneNode) to mockbot-node package
  • now derives from mockbot-node package
  • added outerHTML property (WARNING: only get works, not set)
  • added toString method

Version 0.1.7

  • updated usage example
  • removed client example

Version 0.1.6

  • updated factory create documentation

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

0.1.8

7 years ago

0.1.7

7 years ago

0.1.6

7 years ago

0.1.5

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago