Skip to content

Instantly share code, notes, and snippets.

@akleemans
Created November 9, 2016 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save akleemans/34cd6388d42cab749a94838d0de505bf to your computer and use it in GitHub Desktop.
Save akleemans/34cd6388d42cab749a94838d0de505bf to your computer and use it in GitHub Desktop.
Tests for example controller
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