Created
November 9, 2016 06:08
-
-
Save akleemans/34cd6388d42cab749a94838d0de505bf to your computer and use it in GitHub Desktop.
Tests for example controller
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe("ExampleController", function () { | |
var exampleCtrl, $httpBackend, $filter; | |
beforeEach(module('myapp')); | |
beforeEach(inject(function ($controller, _$httpBackend_, _$filter_, _Users_) { | |
$filter = _$filter_; | |
$httpBackend = _$httpBackend_; | |
// respond with some mocked data | |
$httpBackend.whenGET(/...\/users/).respond([{ username: "foo", email: "foo@gmail.com" }, { username: "bar", email: "bar@aol.com" }]); | |
exampleCtrl = $controller('ExampleController', { Users: _Users_ }); | |
$httpBackend.flush(); | |
})); | |
it('should load user data', function () { | |
expect(exampleCtrl.users).toBeTruthy(); | |
expect(exampleCtrl.users.length).toEqual(2); | |
expect(exampleCtrl.users[0].email).toContain('foo'); | |
}); | |
it('should reduce shown users by searchtext', function () { | |
var searchtext = "aol"; | |
var newList = $filter('filter')(exampleCtrl.users, searchtext); | |
expect(newList.length).toEqual(1); | |
}); | |
it('should filter email provider', function () { | |
var aolUser = exampleCtrl.users[1]; | |
var aolprovider = $filter('provider')(aolUser.email); | |
expect(aolprovider).toEqual("aol.com"); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment