testing - 需要有关在 Meteor.js 中使用 Chimp.js/Mocha 进行测试的建议

标签 testing meteor mocha.js chimp.js

我正在尝试自学使用 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 );
              }
            });
        });


    });
});

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

但是,如果我添加

从“/imports/api/clients/clients.js”导入{客户端};

我得到这个错误Error: Cannot find module '/imports/api/clients/clients.js'

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

谢谢

最佳答案

你需要像这样使用 require :

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

See here for an example .

关于testing - 需要有关在 Meteor.js 中使用 Chimp.js/Mocha 进行测试的建议,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40824956/

相关文章:

ruby-on-rails - headless Chrome 空白白屏

testing - 基于浏览器的网络测试

mongodb - Meteor 应用程序定期崩溃并出现 Mongo 错误

meteor - mup设置: Error: Timed out while waiting for handshake

javascript - 对回调中可访问的相同数据进行多个单元测试

linux - 占用空间小的 VMWare Linux 镜像

spring - 使用 HandlerInterceptorAdapter 时如何测试 Spring REST Web 服务?

javascript - 从YouTube Iframe API meteor 包导入YT和YTConfig

javascript - 测试时,Sinon 不会干扰我的实习生功能。 (ExpressJS)

javascript - Mocha 如何确定嵌套级别?