JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://code.angularjs.org/1.1.0/angular.js"></script>
<script src="http://searls.github.com/jasmine-all/jasmine-all-min.js"></script>
<script src="http://code.angularjs.org/1.1.0/angular-mocks.js"></script>
JavaScript
function PeopleListController( $scope, people ) {
$scope.peopleList = people.requestPeople();
people.requestPeople().then( function ( result ) {
$scope.peopleList2 = result;
} );
}
describe( 'People List Controller', function () {
var scope;
var peopleService;
var controller;
var httpBackend;
beforeEach( inject( function ( $rootScope, $controller, $httpBackend, $http ) {
scope = $rootScope.$new();
httpBackend = $httpBackend;
peopleService = {
peopleStore: [{
FirstName: "Jim",
LastName: "Lavin",
Email: "[email protected]",
Bio: "Creator and Host of Coding Smackdown TV"
}],
requestPeople: function () {
return $http.get( 'api/people' ).then( function ( httpResult ) {
return httpResult.data;
} );
}
};
$httpBackend.whenGET( 'api/people' ).respond( peopleService.peopleStore );
controller = $controller( PeopleListController, {
$scope: scope,
people: peopleService
} );
} ) );
it( 'should set peopleList to the resolved promise value',
function () {
httpBackend.flush();
scope.$root.$digest();
expect( scope.peopleList[0].FirstName ).toEqual( "Jim" );
} );
it( 'should set peopleList2 to the resolved promise value',
function () {
httpBackend.flush();
scope.$root.$digest();
expect( scope.peopleList2[0].FirstName ).toEqual( "Jim" );
} );
} );