Timeout requirement when testing Meteor with speed and jasmine

Quite new to meteor, speed and jasmine, so I'm not sure if I am doing something wrong, using Jasmine for something that it is not intended for, or this is exactly how it works.

I find that I need to set timeouts for almost all of my tests in order to get them to pass. If so, or am I doing something wrong?

For example, some tests that I run check validation messages:

    describe("add quote validation", function() {
      beforeEach(function (done) {
        Router.go('addQuote');
        Tracker.afterFlush(function(){
          done();
        });
      });

      beforeEach(waitForRouter);

      it("should show validation when Quote is missing", function(done) {
        $('#quote').val('');
        $('#author').val('Some author');
        Meteor.setTimeout(function(){
          $('#addQuoteBtn').click();
        }, 500);
        Meteor.setTimeout(function(){
          expect($('.parsley-custom-error-message').text()).toEqual("Quote can't be empty.");
          done();
          }, 500);
      });
    }
+4
source share
1 answer

, , , - . , , , .

/mocha/client/lib.coffee, 100% Jasmine, . Coffeescript, coffeescript.org Javascript, .

, ( - , , ), Template to (re), Template.<your_template>.rendered, , . , lib.coffee:

@afterRendered = (template,f)->
    cb = template.rendered
    template.rendered = ->
      cb?()
      template.rendered = cb
      f?()
      return
    return

? "" rendered , Template . ​​, - , rendered, Meteor.

- :

 it.only "should check stuff after routing", (done)->
    try
      Router.go "<somewhere>"
      afterRendered Template.<expected_template>, ->
        <your tests here>
        done()
    catch e
      done(e)

try-catch, , , -.

, , , JS - "/". - -, " " , .

# evaluates if a JQuery element is visible or not
$.fn.visible = -> this.length > 0 and this.css('display') isnt 'none'

# This superduper JQuery helper function will trigger a function when an element becomes visible (display != none). If the element is already visible, it triggers immediately. 
$.fn.onVisible = (fn,it)->
    sel = this.selector
    if this.visible()
      console.log "Found immediately"
      fn?(this)
    else
      counter = 0
      timer = setInterval ->
        counter++
        el = $(sel)
        if el.visible()
          fn?(el)
          clearInterval timer
          console.log "Found on iteration #{counter}"
        else
          it?(el)
      , 50

iterator it, , . - :

$('#modalId').onVisible (el)->
  <tests here>
  done()
, (el)->
  console.log "Waiting for #{el.selector}"

, , it. , "display: hidden" (Bootstrap ). , / .

!

+5

All Articles