Expect Arrays to be equal ignoring order

Edit Jasmine 2.8 adds arrayWithExactContents that will succeed if the actual value is an Array that contains all of the elements in the sample in any order. See keksmasta’s answer Original (outdated) answer If it’s just integers or other primitive values, you can sort() them before comparing. expect(array1.sort()).toEqual(array2.sort()); If its objects, combine it with the … Read more

How do I mock a service that returns promise in AngularJS Jasmine unit test?

I’m not sure why the way you did it doesn’t work, but I usually do it with the spyOn function. Something like this: describe(‘Testing remote call returning promise’, function() { var myService; beforeEach(module(‘app.myService’)); beforeEach(inject( function(_myService_, myOtherService, $q){ myService = _myService_; spyOn(myOtherService, “makeRemoteCallReturningPromise”).and.callFake(function() { var deferred = $q.defer(); deferred.resolve(‘Remote call result’); return deferred.promise; }); } it(‘can … Read more

How do I read an Istanbul Coverage Report?

There are a number of coverage criteria, the main ones being: Function coverage Has each function (or subroutine) in the program been called? Statement coverage Has each statement in the program been executed? Branch coverage Has each branch (also called DD-path) of each control structure (such as in if and case statements) been executed? For … Read more

jasmine: Async callback was not invoked within timeout specified by jasmine.DEFAULT_TIMEOUT_INTERVAL

Having an argument in your it function (done in the code below) will cause Jasmine to attempt an async call. //this block signature will trigger async behavior. it(“should work”, function(done){ //… }); //this block signature will run synchronously it(“should work”, function(){ //… }); It doesn’t make a difference what the done argument is named, its … Read more

How do I focus on one spec in jasmine.js?

When using Karma, you can enable only one test with fit or fdescribe (iit and ddescribe in Jasmine before 2.1). This only runs Spec1: // or “ddescribe” in Jasmine prior 2.1 fdescribe(‘Spec1’, function () { it(‘should do something’, function () { // … }); }); describe(‘Spec2’, function () { it(‘should do something’, function () { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)