Documentation

0.8.3 API docs

Testing

Testing with fbp-spec

Please refer to the fbp-spec usage guide.

Testing with Mocha

In addition to testing tools tailored for flow-based program testing, you can of course test NoFlo components or graphs with regular JavaScript testing frameworks like Mocha.

The easiest way to run a NoFlo component in Mocha is to use NoFlo’s asCallback method which wraps a component or graph into a simple callback function.

Here is an example:

noflo = require 'noflo'

baseDir = 'my-project'
unless noflo.isBrowser()
  chai = require 'chai'
  path = require 'path'
  baseDir = path.resolve __dirname, '../'

describe 'My component', ->
  # Wrap your component into a function
  mycomp = null
  before ->
    # We need to provide the name of the component/graph we're
    # testing, and the project basedir where NoFlo looks for
    # components
    mycomp = noflo.asCallback 'my_project/MyComponent'
      baseDir: baseDir
  # Then run it inside your tests
  it 'should add one to the data it receives', (done) ->
    mycomp 1, (err, result) ->
      # If there was an error, fail the test
      return done err if err
      # Test the result
      chai.expect(result).to.equal 2
      done()