Skip to content
This repository
Browse code

Add stage test for events with related target id

  • Loading branch information...
commit cbb1d92f674736c5035b0ba4d53fe605359acdf3 1 parent e56e9cc
David Aurelio davidaurelio authored

Showing 1 changed file with 30 additions and 8 deletions. Show diff stats Hide diff stats

  1. +30 8 test/stage-spec.js
38 test/stage-spec.js
@@ -105,14 +105,15 @@ define([
105 105 dParent = new DisplayObject,
106 106 dChild = new DisplayObject;
107 107
108   - dParent.id = 1;
109   - dChild.id = 2;
110 108 dChild.parent = dParent;
  109 + var registry = stage.registry.displayObjects = {};
  110 + registry[dParent.id] = dParent;
  111 + registry[dChild.id] = dChild;
111 112
112   - stage.registry.displayObjects = {
113   - 1: dParent,
114   - 2: dChild
115   - };
  113 + afterEach(function() {
  114 + dChild.removeAllListeners();
  115 + dParent.removeAllListeners();
  116 + });
116 117
117 118 it('Triggers correct event on child and parent [bubbles]', function() {
118 119
@@ -128,7 +129,7 @@ define([
128 129 proxy.runMessageListener({
129 130 command: 'userevent',
130 131 data: {
131   - targetId: 2,
  132 + targetId: dChild.id,
132 133 event: eventObject
133 134 }
134 135 });
@@ -152,7 +153,7 @@ define([
152 153 proxy.runMessageListener({
153 154 command: 'userevent',
154 155 data: {
155   - targetId: 2,
  156 + targetId: dChild.id,
156 157 event: eventObject
157 158 }
158 159 });
@@ -162,6 +163,27 @@ define([
162 163
163 164 });
164 165
  166 + it('should add the correct `relatedTarget` property to the event ' +
  167 + 'object if a related target id is passed', function() {
  168 +
  169 + var event, eventType = 'arbitrary';
  170 + dChild.on(eventType, function(event_) {
  171 + event = event_;
  172 + });
  173 +
  174 + stage.handleEvent({
  175 + command: 'userevent',
  176 + data: {
  177 + event: {type: eventType},
  178 + targetId: dChild.id,
  179 + relatedTargetId: dParent.id
  180 + }
  181 + });
  182 +
  183 + expect(event.type).toBe(eventType);
  184 + expect(event.target).toBe(dChild);
  185 + expect(event.relatedTarget).toBe(dParent);
  186 + });
165 187 });
166 188
167 189 describe('sendMessage', function() {

0 comments on commit cbb1d92

Wolfram Kriesing

thats three tests in one, at least three assumptions/expectations

David Aurelio

This once was a test that tested just

expect(event).toEqual({type: eventType, target: dChild, relatedTarget: dParent});

That test always fails, because there is more stuff on the object.
I went the quick route without thinking too much.

I will remove lines 183–184. The interesting and new test is on line 185

Wolfram Kriesing
David Aurelio
Please sign in to comment.
Something went wrong with that request. Please try again.