Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
Re-initializing a backbone collection doesn't unbind events

I'm contributing to the diaspora* social network and most of the front-end code is written with backbone. Jasmine is used to test that javascript code, and I discovered that, depending of the order of the tests, they may fail. The data isn't cleaned correctly between tests.

The project is open-source, so let me link the code directly. This line for example, at the beginning of the test, is sometimes failing saying Expected object not to have properties "reshared: 5", which is the result of a leftover of that test, run before.

However, notice that the collection was correctly reset before the second test run. But if you put a break point just after that line, and enter target.unreadCountByType in the Firefox console, it will print Object { reshared: 5 }. So, calling new app.collections.Notifications(); doesn't actually (completely) reset the collection.

The collection is defined in this file and as you can see, is correctly initialized (unreadCountByType: {}).

I think that the problem lies here. In those lines, there is a binding to userChangedUnreadStatus which is done each time the parse function is called. So I guess that this should be unbinded at some point, put here my investigation is stuck, as I have no idea how backbone works.

If you want to run the test locally, git clone git@github.com:diaspora/diaspora.git, then generate the assets with bin/rake tests:generate_fixtures, launch jasmine with RAILS_ENV=test bin/rake jasmine and then run the test by visting http://localhost:8888/?spec=app.collections.Notifications with your web browser.

Any help welcome!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!