javascriptunit-testingpluginsgruntjsgrunt-plugins

How to write unit tests for a grunt plugin that doesn't write files?


I'm creating a grunt plugin which is responsible for finding URLs in a file and adding those URLs to a variable in the grunt file using

grunt.config.set('urls', urls);

All examples of unit test for Grunt plugins assume that the plugin is going to write a file and then compares that output to a test file with the 'expected' result.

Is there any way to test if my Grunt plugin has set a config variable?


Solution

  • Something like this?

    urlConfigTest: function(test) {
        test.expect(1);
        grunt.config.set('urls','http://foo.example.com');
        test.equal(grunt.config.get('urls'), 'http://foo.example.com', 'Should set foo to the grunt configuration.');
        test.done();
    }