Search code examples
javascriptcoffeescriptsinonbrunchchaplinjs

How to use Sinonjs with bruch-with-chaplin boilerplate


I started out with the Brunch-with-Chaplin boilerplate, but i wanted to add sinon and qunit to the mix. So i added them to the bower.json and installed them with bower install <lib>. It work all very smooth but now i want to access the functionality like this:

Model = require './model'

module.exports = class Collection extends Chaplin.Collection
  # Mixin a synchronization state machine.
  # _(@prototype).extend Chaplin.SyncMachine
  # initialize: ->
  #   super
  #   @on 'request', @beginSync
  #   @on 'sync', @finishSync
  #   @on 'error', @unsync

  # Use the project base model per default, not Chaplin.Model

    model: Model

    initialize: ->
        @on 'request', @reply

    reply: ->
        console.log QUnit # this works
        console.log Sinon # this error's
        console.log 'requested'

UPDATE:

When i manually build with brunch build i got the error

error: [Error: Component JSON file     
"/Users/Simon/Development/myparcel/data/myparcel/bower_components/sinon/.bower.json"
must have `main` property. 
See https://github.com/paulmillr/read-components#README]

So i added "main":"sinon.js" to the file without any luck.


Solution

  • You need to change a little more you need to change "sinon.js" to "lib/sinon.js" and console.log Sinon to console.log sinon because Sinon uses the sinon global not Sinon