Approval Tests Library - Capturing Human Intelligence


Approval Tests Library - Capturing Human Intelligence

Learn more more about Approvals at

Latest Builds

Linux (Travis CI)
Windows (AppVeyor)
Coverage (Coveralls)

Below is a simple getting started using Mocha. We now support Jasmine as well, just replace mocha with Jasmine below and you should be able to get started.

  1. Create a project (folder)
mkdir MyProject
cd MyProject`
  1. Install approvals npm install --save-dev approvals

  2. Install Mocha globally to execute our tests

npm install -g mocha  
  1. Create a sample Mocha test file called test.js.
  .configure(/* options - see below */)
describe('When running some tests', function () {
  it('should be able to use Approvals', function () {
    var data = "Hello World!";
    this.verify(data);  // or this.verifyAsJSON(data) 
  1. Test the file with mocha.
mocha test.js
  1. You should be presented with a diff tool. (if not, you may need to install one)

Approvals Github Wiki!

The default configuration can be overriden by using the .configure(...) as shown below.

    // The strategy for determining which reporter to use will likely 
    // change at some point. For now, you can configure priority here. 
    // What'd I'd prefer is if each project has a configuraiton file 
    // and each user could setup a ~/.approvalConfig file 
    // which would contain their preferred merge/diff tools 
    reporters:  ["p4merge", "opendiff", "tortoisemerge", "gitdiff"],
    // Some diff tools automatically append an EOL to a merge file 
    // Setting this to true helps with those cases... 
    appendEOL: false,
    EOL:  require('os').EOL,
    // This helps keep the project clean of files 
    // that became stale due to removal of test 
    // or after a rename 
    errorOnStaleApprovedFiles: true,
    // On some files or projects a Byte Order 
    // Mark can be inserted and cause issues, 
    // this allows you to force it to be stripped 
    stripBOM: false
  .mocha(__dirname); // or .jasmine(__dirname); 
/* ... */
  • *.approved.* files should be checked into source control.

  • *.received.* files should be IGNORED.

    If you're using Git add this to your .gitignore:


    Another issue that can crop up is the line-endings as git can change the files depending on checking out the file on linux/mac vs windows.

    The suggested fix is to add *.approved.* binary to your .gitattributes

Check out the guidlines!

Copyright (c) 2012-2014 Llewellyn Falco, Jason Jarrett
Licensed under the Apache license.