samedi 4 février 2017

Testing a ReactiveVar in Meteor

I am trying to test a event in a Template. Within the click event, there is a Reactive Var that gets set.

The test is blocked by the Reactive Var.

Any ideas on how I stub or mock a reactive var in a template? I tried adding it to the template (template.reactiveVar = "whatever"), but no go, as I don't think it's writeable.

The ?? indicate where I am wondering what to put.

it('sets a reactive var when a button is clicked', function(){

Template.button.fireEvent('click ', {
    context: { some: 'values'},
    event: {'target': {'text': 'randomText' } },
    templateInstance:new Template('upload', function(e) {
        this.reactiveVar = new ReactiveVar("not clicked)
    })
});

chai.assert.equal(Template.reactiveVar, "clicked")});

// The actual template is below.. 

Template.button.events{(
 'click button': function(evt, template){
   var text = evt.target.text
   template.reactiveVar.set(text)
  }
});

The result is... TypeError: Cannot read property 'set' of undefined

Any ideas?

Aucun commentaire:

Enregistrer un commentaire