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

  • SEARCH
  • Home
  • 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 8465347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:01:07+00:00 2026-06-10T15:01:07+00:00

I am trying to write some test cases (first time) using jasmine describe(Widget App

  • 0

I am trying to write some test cases (first time) using jasmine

describe("Widget App core logic", function () {
  WAPP.widgets = [];

addwidget will add a widget in my WAPP.widgets array

  WAPP.addWidget('testRecord', 'testRecordContent');
  it("added", function () {
        expect(WAPP.widgets.length).toEqual(1);
    });

Remove widget will remove same widget

  WAPP.removeWidget('1'); 
  it("record removed correctly", function () {
        expect(WAPP.widgets.length).toEqual(0);
    })    

After writing second spec my first spec fails as it shows WAPP .widgets is empty. even though at the time of first spec there is a value in WAPP.widgets

  • 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-06-10T15:01:09+00:00Added an answer on June 10, 2026 at 3:01 pm

    The problem here is that you shouldn’t have test code outside of it. The code outside of the it is ran once before the execution of all the test case. What is probably happening in your case is that you delete all the widget before the test even starts.

    What your test code should look like is this :

    describe("Widget App core logic", function () {
      beforeEach(function () {
        WAPP.widgets = [];
      });
    
      it("added", function () {
        WAPP.addWidget('testRecord', 'testRecordContent');
        expect(WAPP.widgets.length).toEqual(1);
      });
    
      it("record removed correctly", function () {
        WAPP.addWidget('1', '1');
        WAPP.removeWidget('1'); 
        expect(WAPP.widgets.length).toEqual(0);
      })    
    
    });
    

    Do note that your test code should be self-contained, all the initialization should be done inside the it or with beforeEach.

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

Sidebar

Related Questions

I'm trying to write some test cases for my Qooxdoo application, and I think
I'm a student, and I'm trying to write and run some test code for
I am trying to write some of my first code in emacs lisp and
I am trying to write some Activity tests for an app, and one particular
I am trying to write some simple predicate using boost::lambda and I am getting
I'm trying to write some unittests using trial for my twisted application, I wrote
I'm trying to write some functions/subroutines in a module that call another function in
I am trying to figure out how to write my Test cases for a
I am trying to write some unit tests against a view model using SimpleMvvmToolkit,
Im trying to write some unit tests for a couple of merthods that are

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.