1

I am using Mocha and Chai.js to test a function which executes git pull in a Terminal and I want to assert that it results in Already up-to-date.

How can I accomplish this? What is the best approach to take?

var assert = require('chai').assert;
var cmd = require('node-cmd');

describe('DEAN-Management', function () {
    describe('Update source', function () {
        it('check for updates', function () {
            cmd.run('git pull');
            assert.??;
        });
    });
});
1

Try to capture the output from cmd.run(git pull');, e.g.

out = cmd.run('git pull');

then assert out.match('Already up-to-date.')

I don't know the exact syntax so adjust as needed.

0

I'm unfamiliar with that command line library you're using but at a glance... The documentation states that cmd.get(command, callback(data)) accepts a command string and returns the results that were output to the callback function. To use it in a test I'd do something like this where assert.include is a partial match of the string "data".

it('your test', function(){
  cmd.get('git pull', function(data){
    assert.include(data, 'Already up-to-date.', 'Optional success message')
  }
});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.