Skip to content

Instantly share code, notes, and snippets.

@chrisjaure
Last active December 30, 2016 09:15
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chrisjaure/6515906 to your computer and use it in GitHub Desktop.
Save chrisjaure/6515906 to your computer and use it in GitHub Desktop.
AngularJS Jasmine test snippets for Sublime Text 2.
<snippet>
<content><![CDATA[
describe('${1:SuiteName}', function() {
var scope, \$httpBackend, initController;
beforeEach(function() {
module('${2:ModuleName}', function(\$provide){
});
inject(function(\$injector) {
var \$rootScope, \$controller;
\$rootScope = \$injector.get('\$rootScope');
\$controller = \$injector.get('\$controller');
\$httpBackend = \$injector.get('\$httpBackend');
scope = \$rootScope.\$new();
initController = function(opts) {
\$controller('${3:ControllerName}', angular.extend({
\$scope: scope
}, (opts || {})));
};
});
});
afterEach(function() {
// \$httpBackend.verifyNoOutstandingExpectation();
// \$httpBackend.verifyNoOutstandingRequest();
scope.\$destroy();
});
it('should pass', function() {
// \$httpBackend.expectGET('').respond(200);
initController();
});
});
]]></content>
<tabTrigger>ng:test:c</tabTrigger>
<scope>source.js</scope>
</snippet>
<snippet>
<content><![CDATA[
describe('${1:SuiteName}', function() {
var elm, scope, isolateScope,
html = '${3:<div>Element Template</div>}';
beforeEach(function() {
module('${2:ModuleName}', function(\$provide){
});
inject(function(\$injector) {
var \$compile, \$templateCache, \$rootScope;
\$compile = \$injector.get('\$compile');
\$rootScope = \$injector.get('\$rootScope');
// \$templateCache = \$injector.get('\$templateCache');
// \$templateCache.put('${4:templateUrl}', '<div></div>');
elm = angular.element(html);
scope = \$rootScope.\$new();
\$compile(elm)(scope);
scope.\$digest();
// isolateScope = elm.isolateScope();
});
});
afterEach(function() {
scope.\$destroy();
});
it('should pass', function() {
});
});
]]></content>
<tabTrigger>ng:test:d</tabTrigger>
<scope>source.js</scope>
</snippet>
<snippet>
<content><![CDATA[
describe('${1:SuiteName}', function() {
var ${3:ServiceName}, scope;
beforeEach(function() {
module('${2:ModuleName}', function(\$provide){
});
inject(function(\$injector) {
var \$rootScope;
\$rootScope = \$injector.get('\$rootScope');
${3:ServiceName} = \$injector.get('${3:ServiceName}');
scope = \$rootScope.\$new();
});
});
afterEach(function() {
scope.\$destroy();
});
it('should pass', function() {
});
});
]]></content>
<tabTrigger>ng:test:s</tabTrigger>
<scope>source.js</scope>
</snippet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment