小编mys*_*une的帖子

单元测试Node.js和WebSockets(Socket.io)

任何人都可以使用WebSockets(Socket.io)为Node.js提供坚如磐石,简单的单元测试吗?

我正在为Node.js使用socket.io,并查看了socket.io-client,以便在测试中建立与服务器的客户端连接.但是,我似乎错过了一些东西.

在下面的示例中,"工作......"永远不会打印出来.

var io = require('socket.io-client')
, assert = require('assert')
, expect = require('expect.js');

describe('Suite of unit tests', function() {

    describe('First (hopefully useful) test', function() {

        var socket = io.connect('http://localhost:3001');
        socket.on('connect', function(done) {
            console.log('worked...');
            done();
        });

        it('Doing some things with indexOf()', function() {
            expect([1, 2, 3].indexOf(5)).to.be.equal(-1);
            expect([1, 2, 3].indexOf(0)).to.be.equal(-1);
        });

    });
});
Run Code Online (Sandbox Code Playgroud)

相反,我只是得到:

  Suite of unit tests
    First (hopefully useful) test
      ? Doing some things with indexOf() 


  1 test complete (26 ms)
Run Code Online (Sandbox Code Playgroud)

有什么建议?

unit-testing websocket node.js socket.io

58
推荐指数
3
解决办法
3万
查看次数

路径转换破坏渲染的视图对象; "错误:路径[blah]中的对象无法找到或被破坏."

当从一个Ember路由转换到另一个Ember路由时,我收到以下错误:

Error: Object in path item_delet could not be found or was destroyed.
Run Code Online (Sandbox Code Playgroud)

在路线的renderTemplate钩子里,我做了很多这样的事情:

this.render('item_delete', { into: 'item_parent', outlet: 'item_delete' });
Run Code Online (Sandbox Code Playgroud)

...并有一个合理的父/子模板树.但是,当一个模板,比如说"item_delete",被渲染成"routeA",然后我点击进入"routeB",然后回到"routeA",我得到了错误.据我所知,当路由器退出"routeA"以防止内存泄漏时,视图对象会被破坏.我不确定为什么重新进入路由不会重新创建/实例化/连接视图.作为旁注,当出现错误时,任何先前呈现的获取此错误消息的视图的路径名称始终缩短一个字符,请注意"item_delet"而不是"item_delete".

我正在使用grunt-ember-templates来编译Handlebars模板,因此发布JSFiddle有点困难.只是想知道是否有人可以"看到"这段代码来标记路由或renderTemplate钩子可能无法重新实例化/连接/等的任何明显原因.渲染的模板.是否有一些"激活/停用"魔法可以阻止视图被破坏?(我意识到面对摧毁视图对象背后的意图,但我愿意听到所有选项.)

我有一个Ember Route地图,看起来像:

App.Router.map(function () {

    this.route('index', { path: '/projects' });
    this.resource('items', { path: '/projects/folders' }, function() {
        this.resource('item', { path: '/:item_id' }, function() {
            this.route('file_uploads', { path: '/file_upload' });
        });
    });

});
Run Code Online (Sandbox Code Playgroud)

我有像这样定义的路线:

App.IndexRoute = Ember.Route.extend({
    redirect: function() {
        this.transitionTo('items');
    }
});

App.ItemsIndexRoute = Ember.Route.extend({

    model: function() {
        // Setting up the model …
Run Code Online (Sandbox Code Playgroud)

handlebars.js ember.js ember-router

7
推荐指数
1
解决办法
2067
查看次数