Wildhoney / EmberSockets

Socket.io (WebSockets) integrated with Ember.js' observer pattern.
http://ember-sockets.herokuapp.com/
MIT License
136 stars 22 forks source link

Testing #44

Closed vhf closed 9 years ago

vhf commented 9 years ago

First of all, thanks for your good work.

I did not find anything in the README about testing. How would you go about unit testing (qunit w/ember-cli) an app using EmberSockets?

Also, my app works great with EmberSockets, but the first qunit test SocketioInitializer fails with

beforeEach failed on it works: You have forgotten to add EmberSockets into Ember.Application! See: https://github.com/Wildhoney/EmberSockets#getting-started

(ember-sockets 0.6.10, ember-cli 0.1.9)

Wildhoney commented 9 years ago

I rarely use QUnit, so it's difficult for me to comment specifically on that, but did you add EmberSockets to your Ember.Application when bootstrapping the unit-tests? I assume you have, so I'm afraid I'm not quite sure on that.

However, generally, in testing EmberSockets it should simply be a case of obtaining an instance of it, and then invoking emit with your expected events. Ensure that the necessary functions are invoked using spies – Jasmine have native spies with spyOn, but I'm not entirely sure how you would implement spies in QUnit.

Do you have any unit-test implementation which I can take a look at, please?

vhf commented 9 years ago

did you add EmberSockets to your Ember.Application when bootstrapping the unit-tests?

I did not. Any idea where I should do this?

When I put

var Socket = EmberSockets.extend({
    host: 'localhost',
    secure: false,
    port: 8444,
    controllers: [
        'channels/index',
    ],
    autoConnect: true
});

In my start-app.js, I got an "EmberSockets is not defined" error.

Wildhoney commented 9 years ago

You also need to include EmberSockets as part of your unit-tests :+1:

jorgedavila25 commented 9 years ago

having this same issue. not entirely sure how to add EmberSockets to my unit-tests. any tips? thanks

Wildhoney commented 9 years ago

Did @vhf have any luck with his integration?

vhf commented 9 years ago

Nope.

jorgedavila25 commented 9 years ago

@Wildhoney @vhf so i sort of kind of figured it out:

in my acceptance tests, i used application.__container__.lookup('socket:main'); to get an instance of the class. then using sinon.js, i stubbed the methods out. this helped me test

additionally, i had to make some changes to the source to make stubbing easier

See PR: https://github.com/Wildhoney/EmberSockets/pull/51

Wildhoney commented 9 years ago

That's good :+1: For PR #51 I would recommend Ember specific functions though, as @fsmanuel pointed out.