Unit testing classes or parts of a p5.js sketch?

Hello!

I am looking to unit test some of my code. My instinct was to use mocha and chai assertion libraries but I wanted to see if anyone else had done some of this with a processing sketch before and had any tips/best practices?

Cheers

Answers

  • Building it with Mocha and Chai! It works!

  • @andrewjtimmons:

    Could you grace us with an example of how you wrote your mocha tests? The first things I stumbled on was how to require() the requisite p5 module. If I simply put

    var p5 = require('../libraries/p5.js')
    

    at the head of my test file, then mocha errors out with

    window.requestAnimationFrame = (function(){
    ^
    ReferenceError: window is not defined
    

    Then there's the small matter of how you wrap a p5 instance around the entire test, but I'm happy to take one step at a time. :)

Sign In or Register to comment.