2

私はモカ/オムフにとても慣れていません。以下の基本的なテストがあります。

omf('http://localhost:7000', function(client) {
  client.get('/apps', function(response){
    response.has.statusCode(200);
    response.has.body('["test1","test2"]');
  });
});

値「test2」が返されたリストに含まれているかどうかを確認したいのですが、これがどのように実現可能かわかりません。私は次のようなことを考えています:

omf('http://localhost:7000', function(client) {
  client.get('/apps', function(response){
    response.has.statusCode(200);
    // response.body.split.contains("test2"); // Something like that
  });
});

response.body にアクセスして、文字列を解析できますか?

** アップデート **

シンプルなステータスコードであるmochaでテストしようとしました:

request = require("request");

describe('Applications API', function(){
  it('Checks existence of test application', function(done){
    request
      .get('http://localhost:7000/apps')
      .expect(200, done);
  });
});

しかし、次のエラーが発生しました:

TypeError: オブジェクト # にはメソッド 'expect' がありません

何か案が ?モカには追加のアドオンが必要ですか?

4

1 に答える 1

7

2 番目の例は、示されているようには機能しません。request.get は非同期です。

リクエストで実行する実際の例を次に示します。

request = require("request");
should = require("should");

describe('Applications API', function() {
  it('Checks existence of test application', function(done) {
    request.get('http://google.com', function(err, response, body) {
      response.statusCode.should.equal(200);
      body.should.include("I'm Feeling Lucky");
      done();
    })
  });
});
于 2013-02-19T20:15:16.657 に答える