Last active
August 29, 2015 14:13
-
-
Save ryanand26/e03d6eacab6c474a34df to your computer and use it in GitHub Desktop.
Karma configuration
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
// given relative path test/fixtures/ to karma | |
// Important: These paths must be exposed in karma.conf.js | |
var path = ''; | |
if (typeof window.__karma__ !== 'undefined') { | |
path += 'base/'; | |
} | |
jasmine.getFixtures().fixturesPath = path + 'test/fixtures'; | |
jasmine.getJSONFixtures().fixturesPath = path + 'test/fixtures'; | |
/** | |
* Mock the service responders | |
*/ | |
beforeEach(inject(function($injector) { | |
// Set up the mock http service responses | |
$httpBackend = $injector.get('$httpBackend'); | |
//form submission | |
submissionResponder = $httpBackend.whenGET(/^\/api\/v1\/export*/); | |
submissionResponder | |
.respond('RESPONSE'); | |
})); | |
afterEach(function() { | |
$httpBackend.verifyNoOutstandingExpectation(); | |
$httpBackend.verifyNoOutstandingRequest(); | |
}); | |
/** | |
* Filter | |
*/ | |
describe('Filter: obscureString', function () { | |
// load the filter's module | |
beforeEach(module('tngApp')); | |
// initialize a new instance of the filter before each test | |
var filterInstance; | |
beforeEach(inject(function ($filter) { | |
filterInstance = $filter('obscureString'); | |
})); | |
it('should return the input prefixed with "obscureString filter:"', function () { | |
var input = '12345678', | |
characterCount = 4, | |
replacementCharacter = 'x', | |
result; | |
result = filterInstance(input, characterCount, replacementCharacter); | |
expect(result).toBe('xxxx5678'); | |
}); | |
}); | |
/** | |
* Service | |
*/ | |
beforeEach(inject(function (_UserService_) { | |
UserService = _UserService_; | |
})); | |
/** | |
* Controller and mock scope | |
*/ | |
beforeEach(inject(function ($rootScope, $controller) { | |
//setup the top level scope | |
topScope = $rootScope.$new(); | |
$controller('AppCtrl', { | |
$scope: topScope | |
}); | |
//create controller scope | |
scope = topScope.$new(); | |
thisCtrl = $controller('MainCtrl', { | |
$scope: scope | |
}); | |
})); | |
/* | |
* Directives | |
*/ | |
beforeEach(inject(function ($rootScope, $compile) { | |
var elementHTML = jasmine.getFixtures().read('source.html'); | |
parentScope = $rootScope.$new(); | |
//fake the parent directive | |
parentScope.payments = { | |
fromaccount : fromAccountId, | |
toaccount : '' | |
}; | |
parentScope.isTransfer = false; | |
scope = parentScope.$new(); | |
element = angular.element(elementHTML); | |
element = $compile(element)(scope); | |
})); | |
/** | |
* Mock cookies | |
*/ | |
beforeEach(angular.mock.module('ngCookies', 'tngApp')); | |
/** | |
* Provide a mock | |
*/ | |
beforeEach(module('myApp', function ($provide) { | |
var mockMapApi = { | |
get : function() { | |
return { | |
then : function (callback) { | |
suppliedCallback = callback; | |
} | |
}; | |
} | |
}; | |
$provide.value('mapApi', mockMapApi); | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment