0.0.2 • Published 7 years ago

mockdoc v0.0.2

Weekly downloads
3
License
BSD-3-Clause
Repository
github
Last release
7 years ago

MockDoc - Mock document for tests

Usage

And('DOM is loaded', () => {
  global.document = new Mockdock();
  require('app.js');
});
let testValue;

When('DOM is loaded', () => {
  global.document = new Mockdock();
  global.document.body = new Mockdock();
  global.document.body.on('setAttribute', (value) => {
    testValue = value;
  });
});

Then('app is started', () => {
  require('app.js');
  testValue.should.equal('some-attribute');
})

Events

global.document.on('setAttribute', (value) => {}));

global.document.on('removeAttribute', (value) => {}));

global.document.on('DOMContentLoaded', () => {});

global.document.on('appendChild', (element) => {}));

global.document.domContentLoaded()

global.document.triggerEventListener(type)

Supported node functions

addEventListener(type, fn)

createElement(type)

getElementsByTagName(tag)

removeAttribute(attrName)

setAttribute(cmd, value)

hasAttribute(attrName)

getElementById(id)

querySelector(selectors)

querySelectorAll()

getAttribute(name)

appendChild(element)