0.2.0 • Published 8 years ago

nightmare-custom-event v0.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

nightmare-custom-event

Allows for adding custom events to Nightmare.

Usage

Require the library and pass the Nightmare library as a reference to attach the plugin actions:

var Nightmare = require('nightmare');
require('nightmare-custom-event')(Nightmare);

... and then you're able to use bind and unbind.

.bind(name , handler)

Adds a custom event that can be captured with .on() triggerable in .evaluate() or .inject() with ipc.send([name], ...). The optional handler will consume the named event.

.unbind(name , handler)

Removes a custom event added with .bind(). If handler is specified, the handler is removed. If no handler is specified or the handler was the last handler for the emitter, the custom event is removed and will no longer be emittable until it is bound again.

Example

var onResults;
yield nightmare
  .goto(fixture('events'))
  .bind('sample-event', handler)
  .on('sample-event', function(msg) {
    onResults = msg.sample;
   })
   .evaluate(function() {
     ipc.send('sample-event', 'sample', 3, {
       sample: 'sample'
      });
   });

// ... do something intermediate ...

yield nightmare.
    unbind('sample-event');
0.2.0

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago

0.1.1

8 years ago

0.1.0

8 years ago