Skip to content

Commit

Permalink
Delete blank line, add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
natseg committed Jun 2, 2017
1 parent 43d8503 commit 4144faf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
3 changes: 1 addition & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class Entity extends React.Component {

// Allow ref.
if (props._ref) { props._ref(el); }
}
};

/**
* Handle updates after the initial render.
Expand All @@ -97,7 +97,6 @@ export class Entity extends React.Component {
const props = this.props;

if (props.events) {

// Remove events.
Object.keys(props.events).forEach(eventName => {
removeEventListeners(el, eventName, props.events[eventName]);
Expand Down
31 changes: 30 additions & 1 deletion tests/browser/index.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import {Entity, doSetAttribute, Scene} from '../../src/index.js';
import {Entity, Scene} from '../../src/index.js';

const div = document.createElement('div');
document.body.appendChild(div);
Expand Down Expand Up @@ -310,6 +310,35 @@ suite('<Entity events/>', () => {
});
});

test('can remove event listener when component is detached', function (done) {
let bazHandlerCalled = false;
function bazHandler () { bazHandlerCalled = true }

ReactDOM.render(
<Scene>
<Entity id='foo'>
<Entity id='bar' events={{baz: bazHandler}}/>
</Entity>
</Scene>,
div
);
div.querySelector('a-scene').addEventListener('loaded', () => {
ReactDOM.render(
<Scene>
<Entity id='foo'/>
</Scene>,
div
);
div.querySelector('a-entity').emit('baz');
setTimeout(() => {
assert.ok(div.querySelector('#foo'));
assert.notOk(div.querySelector('#bar'));
assert.notOk(bazHandlerCalled);
done();
});
});
});

test('can attach extra event listener', function (done) {
let fooHandlerCalled = false;
let barHandlerCalled = false;
Expand Down

0 comments on commit 4144faf

Please sign in to comment.