Skip to content

Instantly share code, notes, and snippets.

View rolaveric's full-sized avatar

Jason Stone rolaveric

View GitHub Profile
@rolaveric
rolaveric / jasmineTest.js
Last active January 4, 2016 15:19
Jasmine test
describe('triple', function () {
it('Triples the value passed to it', function () {
expect(triple(3)).toEqual(9);
});
});
@rolaveric
rolaveric / serviceSimple.js
Last active January 4, 2016 15:19
AngularJS Unit Test: Service, simple
describe('myService', function () {
beforeEach(module('MyModule'));
it('Contains property "myProperty"', inject(function (myService) {
expect(myService.myProperty).not.toBeUndefined();
});
});
@rolaveric
rolaveric / serviceComplex.js
Last active January 4, 2016 15:19
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;
@rolaveric
rolaveric / dependenciesSimple.js
Last active January 4, 2016 15:19
AngularJS Unit Test: Dependencies, simple
it('Calls anotherService.anotherMethod()', inject(function (myService, anotherService) {
spyOn(anotherService, 'anotherMethod');
myService.myMethod({});
expect(anotherService.anotherMethod).toHaveBeenCalled();
}));
@rolaveric
rolaveric / dependenciesComplex.js
Created January 26, 2014 22:13
AngularJS Unit Test: Dependencies, complex
beforeEach(inject(function (anotherService) {
spyOn(anotherService, 'anotherMethod');
}));
it('Calls anotherService.anotherMethod() during construction', inject(function (myService) {
expect(anotherService.anotherMethod).toHaveBeenCalled();
}));
@rolaveric
rolaveric / filterSimple.js
Created January 26, 2014 22:14
AngularJS Unit Test: Filter, simple
it('Capitalises strings', inject(function (capitaliseFilter) {
expect(capitaliseFilter('abcd')).toEqual('Abcd');
}));
@rolaveric
rolaveric / filterComplex.js
Created January 26, 2014 22:16
AngularJS Unit Test: Filter, complex
it('Capitalises strings', inject(function ($filter) {
expect($filter('capitalise')('abcd')).toEqual('Abcd');
}));
@rolaveric
rolaveric / controllerFakeScope.js
Created January 26, 2014 22:17
AngularJS Unit Test: Controller, fake scope
it('Attaches the scope to itself', inject(function ($controller) {
var fakeScope = {};
var ctrl = $controller('MyCtrl', "$scope": fakeScope});
expect(ctrl.scope).toBe(fakeScope);
}));
@rolaveric
rolaveric / controllerRealScope.js
Created January 26, 2014 22:18
AngularJS Unit Test: Controller, real scope
it('Attaches the scope to itself', inject(function ($controller, $rootScope) {
var scope = $rootScope.$new();
var ctrl = $controller('MyCtrl', "$scope": scope});
expect(ctrl.scope).toBe(scope);
}));
@rolaveric
rolaveric / controllerTemplate.js
Created January 26, 2014 22:20
AngularJS Unit Test: Controller, template
describe('MyCtrl', function () {
var ctrl, scope, service;
beforeEach(inject(function ($controller, $rootScope, myService) {
service = myService;
scope = $rootScope.$new();
ctrl = $controller('MyCtrl', {"$scope": scope, "myService": service});
}));
describe('doSomething()', function () {