You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by br...@apache.org on 2018/12/18 15:00:38 UTC
[cordova-common] 02/02: Add Cordova events emit tests
This is an automated email from the ASF dual-hosted git repository.
brodybits pushed a commit to branch brodybits-events-updates
in repository https://gitbox.apache.org/repos/asf/cordova-common.git
commit 8030af13b440dc2ffc0b4aafeb4130ee49245368
Author: Christopher J. Brody <ch...@gmail.com>
AuthorDate: Tue Dec 18 09:27:49 2018 -0500
Add Cordova events emit tests
with other minor Cordova events test updates
Co-authored-by: Christopher J. Brody <ch...@gmail.com>
Co-authored-by: daserge <v-...@microsoft.com>
---
spec/events.spec.js | 29 ++++++++++++++++++++++++++---
1 file changed, 26 insertions(+), 3 deletions(-)
diff --git a/spec/events.spec.js b/spec/events.spec.js
index 2fa8453..7209c37 100644
--- a/spec/events.spec.js
+++ b/spec/events.spec.js
@@ -20,28 +20,51 @@
var events = require('../src/events');
describe('Cordova events', function () {
+ it('Test 001 : should emit events to a listener', function () {
+ var logSpy = jasmine.createSpy('logSpy');
+ events.on('log', logSpy);
+
+ events.emit('log', 'a test message');
+ expect(logSpy).toHaveBeenCalledWith('a test message');
+ });
+
describe('forwardEventsTo method', function () {
afterEach(function () {
events.forwardEventsTo(null);
});
- it('Test 001 : should not go to infinite loop when trying to forward to self', function () {
+
+ it('Test 002 : should forward events to another event emitter', function () {
+ var EventEmitter = require('events').EventEmitter;
+ var anotherEventEmitter = new EventEmitter();
+ var logSpy = jasmine.createSpy('logSpy');
+ anotherEventEmitter.on('log', logSpy);
+
+ events.forwardEventsTo(anotherEventEmitter);
+ events.emit('log', 'forwarding test message');
+ expect(logSpy).toHaveBeenCalledWith('forwarding test message');
+ });
+
+ it('Test 003 : should not go to infinite loop when trying to forward to self', function () {
expect(function () {
events.forwardEventsTo(events);
events.emit('log', 'test message');
}).not.toThrow();
});
- it('Test 002 : should reset forwarding after trying to forward to self', function () {
+
+ it('Test 004 : should reset forwarding after trying to forward to self', function () {
var EventEmitter = require('events').EventEmitter;
var anotherEventEmitter = new EventEmitter();
var logSpy = jasmine.createSpy('logSpy');
anotherEventEmitter.on('log', logSpy);
+ // should forward events to another event emitter at this point
events.forwardEventsTo(anotherEventEmitter);
events.emit('log', 'test message #1');
- expect(logSpy).toHaveBeenCalled();
+ expect(logSpy).toHaveBeenCalledWith('test message #1');
logSpy.calls.reset();
+ // should *not* forward events to another event emitter at this point
events.forwardEventsTo(events);
events.emit('log', 'test message #2');
expect(logSpy).not.toHaveBeenCalled();
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org