Skip to content

Instantly share code, notes, and snippets.

@rolaveric
Last active January 4, 2016 15:19
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 rolaveric/8640009 to your computer and use it in GitHub Desktop.
Save rolaveric/8640009 to your computer and use it in GitHub Desktop.
AngularJS Unit Test: Service, complex
// Group by module
describe('MyModule', function () {
// Initialise the module for each test
beforeEach(module('MyModule'));
// Group by service
describe('myService', function () {
var service;
// Setup for each test
beforeEach(inject(function (myService) {
// Every test I'm going to want an instance of "myService"
service = myService;
}));
// Tests for the newly constructed service
it('Contains property "myProperty"', function () {
expect(service.myProperty).not.toBeUndefined();
});
// Grouping tests by method
describe('myMethod(input)', function () {
it('Returns the input', function () {
var a = {};
expect(service.myMethod(a)).toBe(a);
});
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment