小编iva*_*van的帖子

在节点的mocha js中使用全局窗口变量

我是js单元测试的新手,我正在尝试使用mocha作为我在这个github repo上找到的骨干联系管理器教程.但是,我有一个全局window.ContactManager变量,我想要测试它是否存在,然后测试启动函数内的router.on功能.变量看起来像这样:

  window.ContactManager = {
  Models: {},
  Collections: {},
  Views: {},

  start: function(data) {
    var contacts = new ContactManager.Collections.Contacts(data.contacts),
        router = new ContactManager.Router();

    router.on('route:home', function() {
      router.navigate('contacts', {
        trigger: true,
        replace: true
      });
    });

    router.on('route:showContacts', function() {
      var contactsView = new ContactManager.Views.Contacts({
        collection: contacts
      });
.....
Run Code Online (Sandbox Code Playgroud)

我的测试不起作用:var expect = require('chai').expect;

describe("Application", function() {
    it('creates a global variable for the name space ContactManager' , function () {
        expect(ContactManager).to.exist;
    })
});
Run Code Online (Sandbox Code Playgroud)

如何通过在控制台中运行测试来测试和访问mocha中的全局窗口变量?

javascript mocha.js node.js backbone.js chai

13
推荐指数
1
解决办法
2万
查看次数

如何在更改模型后创建Sequelize cli db迁移

我从sequelize开始,并在线跟踪他们的视频教程.跑完之后

node_modules/.bin/sequelize model:create --name User --attributes username:string

node_modules/.bin/sequelize model:create --name Task --attributes title:string
Run Code Online (Sandbox Code Playgroud)

它为create user和create task创建了迁移文件.然后我必须将关联添加到每个模型,如下所示:

// user.js
classMethods: {
  associate: function(models) {
    User.hasMany(models.Task);
  }
}

// task.js
classMethods: {
  associate: function(models) {
    Task.belongsTo(models.User);
  }
}
Run Code Online (Sandbox Code Playgroud)

但是,已创建用于为用户和任务创建表的迁移文件.我是否必须手动更新它们以添加关系?"migration:create"命令用于创建迁移框架文件.我是否手动填写框架文件,或者除了模型创建之外还有自动创建完整迁移文件的方法吗?

PS我已经看到了以下stackoverflow问题: 如何使用Sequelize模型中的Sequelize CLI自动生成迁移?

orm node.js sequelize.js

12
推荐指数
1
解决办法
5333
查看次数

Where Does Meteor Store It's Data?

I have just started playing around with Meteor and MongoDB for the first time. I come from a .net developer background and MSSQL. I have created a simple web following this tutorial. Also, I have added the accounts-password package to my app as well. Everything works like a charm, I can add data to my application in real time and I can create users and login, etc, etc. However, when I open up Robomongo and look for the stored …

javascript mongodb meteor

6
推荐指数
1
解决办法
2797
查看次数

使用REST API时,Meteor是否保留反应性

我打算使用Qualtrics REST API,以便从调查中收集数据.我是否仍然可以通过其他API直接保留Meteor的反应性,还是应该将其余API中的数据保存到MongoDB中以实现应用内的实时更新?

任何建议和进一步阅读都会很棒.

这听起来像是一个noob问题,但我刚开始使用Meteor和JS作为服务器端代码,之前从未使用过web api.

javascript rest node.js meteor qualtrics

6
推荐指数
1
解决办法
1207
查看次数

使用jquery选择器计算html表中的列和行总和

我试图计算html表中的行和列总数.但是,我试图计算行总计直到倒数第二列.我可以做到最后一栏,但不是倒数第二.我还想从第一列中删除Total:0.能帮到我吗,下面是我的代码:

<table id="sum_table" width="300" border="1">
        <tr class="titlerow">
            <td></td>
            <td>Apple</td>
            <td>Orange</td>
            <td>Watermelon</td>
            <td>Total By Row</td>
            <td>Strawberry</td>            
        </tr>
        <tr>
            <td> Row1</td>
            <td class="rowAA">1</td>
            <td class="rowAA">2</td>
            <td class="rowBB">3</td>
            <td class="totalRow"></td>
            <td class="rowBB">4</td>

        </tr>
        <tr>
            <td> Row2</td>
            <td class="rowAA">1</td>
            <td class="rowAA">2</td>
            <td class="rowBB">3</td>
            <td class="totalRow"></td>
            <td class="rowBB">4</td>

        </tr>
        <tr>
            <td>Row3</td>
            <td class="rowAA">1</td>
            <td class="rowAA">5</td>
            <td class="rowBB">3</td>
            <td class="totalRow"></td>
            <td class="rowBB">4</td>
        </tr>
        <tr class="totalColumn">
            <td class="totalCol"></td>
            <td class="totalCol"></td>
            <td class="totalCol"></td>
            <td class="totalCol"></td>
            <td class="totalCol"></td>
            <td class="totalCol"></td>
        </tr>
</table>
Run Code Online (Sandbox Code Playgroud)

JS:

$("#sum_table tr:not(:first,:last)  td:nth-last-child(2)").text(function(){
    var t = …
Run Code Online (Sandbox Code Playgroud)

javascript jquery html5

0
推荐指数
1
解决办法
2万
查看次数