npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mockbot-element

v0.1.8

Published

mock html dom element

Downloads

8

Readme

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

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

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

| 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

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