How to test window.location.href using jasmine

Syed Rasheed

This is my controller code

$scope.loadApplications = function () {
      var cacheKey = { key: cacheKeys.appList() };
      dataFactory.get("/Application/All", { cache: cacheKey })
             .then(function (result) {
                 $scope.count++;                     
                 $scope.applications = result.data.data;
                 $scope.filteredApplicationsList = $scope.applications;
                  if ($scope.applications.length===0){
                     $window.location.href = '/Account/WelCome'
                 }
                 else {
                     $scope.isLoad = true;
                  }

             });
  };

and this is my jasmine test cases for above function

  it('should redirect to welcome page', function () {
        scope.applications = {};
        scope.loadApplications();
        expect(window.location.href).toContain('/Account/WelCome');
    });

but it is taking the current url of browser and it is raising an error as

Expected 'http://localhost:49363/Scripts/app/test/SpecRunner.html' to contain '/Account/WelCome'.

can anybody please tell me how to test the url?

RIYAJ KHAN

you should write it in this way.

it('should redirect to welcome page', function () {
        scope.applications = {};
        scope.loadApplications();

        browser.get('http://localhost:49363/Account/WelCome');
        expect(browser.getCurrentUrl()).toEqual('whateverbrowseryouarexpectingtobein');
        expect(browser.getCurrentUrl()).toContain('whateverbrowseryouarexpectingtobein');

        //expect(window.location.href).toContain('/Account/WelCome');
    });

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Java

How to mock window.location.href with Jest + Vuejs?

From Dev

How to unit test a chained method using Jasmine

From Dev

Javascript: How to catch error on page navigated to using window.location.href = url

From Dev

How to test the duration of a $timeout operation using jasmine?

From Dev

javascript testing using sinon.js & Qunit. how to test for window.location.href and avoid downloading

From Dev

How to test DOM and CSS using Jasmine and Karma

From Dev

How to avoid location.reload() in angular tests via jasmine, and test it

From Dev

How to test _.defer() using Jasmine, AngularJs

From Dev

How would I test window prompts and confirms with Karma / Jasmine?

From Dev

How to mock a window.location function in Karma/jasmine

From Dev

Using a variable for if window.location.href.indexOf()

From Dev

Why isnt window.location.href= not forwarding to page using Safari?

From Dev

how to test $window.open using jasmine

From Dev

Redirect a Website to a local folder Using window.location.href() not working

From Dev

How to write test using Jasmine and AngularJS?

From Dev

how to specify csv file name for downloading in window.location.href

From Dev

Cannot change to different windows using window.location.href

From Dev

How to test code inside $(window).on("load", function() {}); in Jasmine

From Dev

No output to iframe after using window.location.href

From Dev

How to test spy in setTimeout using jasmine?

From Dev

How to make sure code runs before window.location.href

From Dev

How to pass Id value to window.location.href in MVC application

From Dev

How to Pass QueryString in window.location.href?

From Dev

How to test DOM and CSS using Jasmine and Karma

From Dev

How to avoid location.reload() in angular tests via jasmine, and test it

From Dev

Look for a string in URL using test and location.href

From Dev

Passing parameters using Window.location.href

From Dev

How to use a dynamically generated id in window.location.href?

From Dev

No output to iframe after using window.location.href

Related Related

  1. 1

    How to mock window.location.href with Jest + Vuejs?

  2. 2

    How to unit test a chained method using Jasmine

  3. 3

    Javascript: How to catch error on page navigated to using window.location.href = url

  4. 4

    How to test the duration of a $timeout operation using jasmine?

  5. 5

    javascript testing using sinon.js & Qunit. how to test for window.location.href and avoid downloading

  6. 6

    How to test DOM and CSS using Jasmine and Karma

  7. 7

    How to avoid location.reload() in angular tests via jasmine, and test it

  8. 8

    How to test _.defer() using Jasmine, AngularJs

  9. 9

    How would I test window prompts and confirms with Karma / Jasmine?

  10. 10

    How to mock a window.location function in Karma/jasmine

  11. 11

    Using a variable for if window.location.href.indexOf()

  12. 12

    Why isnt window.location.href= not forwarding to page using Safari?

  13. 13

    how to test $window.open using jasmine

  14. 14

    Redirect a Website to a local folder Using window.location.href() not working

  15. 15

    How to write test using Jasmine and AngularJS?

  16. 16

    how to specify csv file name for downloading in window.location.href

  17. 17

    Cannot change to different windows using window.location.href

  18. 18

    How to test code inside $(window).on("load", function() {}); in Jasmine

  19. 19

    No output to iframe after using window.location.href

  20. 20

    How to test spy in setTimeout using jasmine?

  21. 21

    How to make sure code runs before window.location.href

  22. 22

    How to pass Id value to window.location.href in MVC application

  23. 23

    How to Pass QueryString in window.location.href?

  24. 24

    How to test DOM and CSS using Jasmine and Karma

  25. 25

    How to avoid location.reload() in angular tests via jasmine, and test it

  26. 26

    Look for a string in URL using test and location.href

  27. 27

    Passing parameters using Window.location.href

  28. 28

    How to use a dynamically generated id in window.location.href?

  29. 29

    No output to iframe after using window.location.href

HotTag

Archive