daniellmb / angular-test-patterns

A High-Quality Guide for Testing Angular 1.x
MIT License
867 stars 100 forks source link

Checking if controller exists #1

Closed padsbanger closed 11 years ago

padsbanger commented 11 years ago

Hello, can you explain me something ?

In controllers testing pattern you have something like this:

var myCtrl;

// Initialize the controller and scope beforeEach(function () { // Load the controller's module module('myApp');

// create contreoller
inject(function ($controller,) {
  scope = {};
  myCtrl = $controller('myCtrl', {
    $scope: scope
  });
});

});

// Now time for test Can you explaing why this test is passing

it('should exist', function () { expect(!!myCtrl).toBe(true); });

// and this one

it('should exist', function () { expect(myCtrl).toBe(true); });

// is throwing an error like this:

Expected {  } to be true.
Error: Expected {  } to be true.

Isnt something like this !!true === true, actuall true ?

daniellmb commented 11 years ago

!! is just a simple way to convert to a boolean. So if the controller object was created it would be true, and if the value of myCtrl null or undefined etc. then it will be false.

padsbanger commented 10 years ago

Ok, cool tip, thanks :)