【问题标题】:Need advice about testing using Chimp.js/Mocha in Meteor.js需要有关在 Meteor.js 中使用 Chimp.js/Mocha 进行测试的建议
【发布时间】:2016-11-27 01:35:48
【问题描述】:

我正在尝试自学使用 Meteor 进行测试,但是网上有太多相互矛盾和过时的信息,我真的很难弄清楚我需要做什么。

我目前的情况是我有一个使用最新 Meteor 版本(和导入文件夹结构)的应用程序。

我已经全局安装了 chimp 并创建了一个 /tests 目录。

我的第一个测试是使用 chimp/mocha 填写表格并尝试向数据库中插入一些内容。我也在使用 xolvio/backdoor 包并像这样运行 chimp

chimp --ddp=http://localhost:3000 --mocha --path=tests

这是我的测试代码:

describe('Chimp Mocha', function() {
    describe( 'Create a Client', function() {

        it( 'should fill in add client form', function() {
            browser.setValue('#clientName', 'Test')
                    .setValue('#clientEmail', 'test@test.com')
                    .selectByValue('#numberTeamMembers', '25')
                    .submitForm('#createClient')
        });

        it( 'should check the collections for new client data', function() {
            let getClient = server.execute( function() {
              return Clients.findOne({ name: 'Test' });
            });

            expect( getClient.name ).to.equal( 'Test' );
        });

        after( function() {
            server.execute( function() {
              let client = Clients.findOne( { name: 'Test' } );
              if ( client ) {
                Clients.remove( client._id );
              }
            });
        });


    });
});

这是抛出一个客户端未定义的错误

但是,如果我添加

import { Clients } from '/imports/api/clients/clients.js';

我收到此错误Error: Cannot find module '/imports/api/clients/clients.js'

我做错了什么?我应该使用黑猩猩吗?任何帮助都将不胜感激,因为我觉得 Meteor 指南对此不太清楚!

谢谢

【问题讨论】:

    标签: testing meteor mocha.js chimp.js


    【解决方案1】:

    你需要像这样使用require:

    require('/imports/api/clients/clients').Clients

    See here for an example.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多