Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6712707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:17:29+00:00 2026-05-26T08:17:29+00:00

Jasmine Test: describe ‘Toolbar’, -> beforeEach -> jasmine.getFixtures().fixturesPath = ../spec/javascript/fixtures loadFixtures(canvas_fixture.html) describe ‘Rectangle Button

  • 0

Jasmine Test:

describe 'Toolbar', ->
  beforeEach ->
    jasmine.getFixtures().fixturesPath = "../spec/javascript/fixtures"
    loadFixtures("canvas_fixture.html")

  describe 'Rectangle Button Click', ->
    it 'adds the selected class to rectangle button', ->
      toolbar = new Toolbar()
      expect(toolbar).toBeDefined
      console.log $('#rectangle')
      toolbar.rectangle
      expect($('#rectangle').hasClass("selected")).toBeTruthy()
      console.log $('#rectangle')

Class:

class window.Toolbar
  jQuery ->
    rectangle: $('#rectangle').click ->
      $('#toolbar button').removeClass("selected")
      $('#rectangle').addClass("selected")

This test is failing for me as the selected class is not being added to the fixture, and I think I’m not calling the function correctly. How do I call the

$(‘#rectangle’).click

function in my test? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:17:29+00:00Added an answer on May 26, 2026 at 8:17 am

    I don’t know the whole context, but some things I see:

    • toolbar.rectangle in your test is not calling a function, you need to say toolbar.rectangle() to actually call it
    • Your class as written is not defining a method on the Toolbar class, you should write something like this:

      class Toolbar
        rectangle: ->
          $('#rectangle').click ->
            $('#toolbar button').removeClass("selected")
            $('#rectangle').addClass("selected")
      
    • When you write this $('#rectangle').click -> ..., you are defining an event handler that will get called when you click in #rectangle. If you want to have it have action immediately (i.e. when you call toolbar.rectangle(), you need something like this:

      class Toolbar
        rectangle: ->
          $('#toolbar button').removeClass("selected")
          $('#rectangle').addClass("selected")
      

    Of course, you need to make sure all this happens after the page loads correctly, not familiar with Jasmine to say whether that will happen.

    Hope this helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do we clear the spy in a jasmine test suite programmatically? Thanks. beforeEach(function()
Consider the following jasmine spec: describe(something.act(), function() { it(calls some function of my module,
I'm using the Jasmine BDD Javascript library and really enjoying it. I have test
I have a custom matcher in some Jasmine test specs of the form: this.addMatchers({
I'm writing specs for different test cases for Jasmine and QUnit to compare them
I need to automate tests of our javascript files using Rhino and Jasmine. We
I am unit testing some JavaScript with Jasmine and wish to spy on (mock)
I am writing a mock for the node-redis module and using Jasmine to test
I have the following Jasmine context and assertion: it should return a javascript file,
I'm trying to test some backbone.js views using Jasmine (via jasmine-headless-webkit). Everything is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.