grunt-contrib-templify
Advanced tools
Comparing version
{ | ||
"name": "grunt-contrib-templify", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A simple project for quick and dirty conversion of HTML files to javascript for various cases, particularly unit testing.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -22,3 +22,3 @@ # grunt-contrib-templify | ||
templify: { | ||
//... | ||
// ... | ||
} | ||
@@ -138,3 +138,3 @@ ``` | ||
mode: "karma-angular", | ||
output: "spec/templates.js" | ||
output: "specs/templates.js" | ||
} | ||
@@ -145,10 +145,59 @@ } | ||
Once the grunt process is described, the templify:testing task will need to preceed the karma task for testing. The idea being that the generated javascript file will then be provided to karma, where the declarations for the templates to pass to angular are ready in a function named **__templifyTemplates**. Then inside the jasmine tests: | ||
Once the grunt process is described, the templify:testing task will need to preceed the karma task for testing. The idea being that the generated javascript file will then be provided to karma, where the declarations for the templates to pass to angular are ready in a function named **__templifyTemplates**. Then inside the jasmine tests. | ||
In Karma's Grunt declaration: | ||
```javascript | ||
//... | ||
karma: { | ||
options: { | ||
// ... | ||
files: [ | ||
// Dependencies... | ||
"specs/templates.js", | ||
// Tests... | ||
] | ||
}, | ||
// ... | ||
} | ||
``` | ||
In your Jasmine tests: | ||
```javascript | ||
// ... | ||
/* Creates a beforeEach clause in Jasmine to bind the templates to the Template cache */ | ||
__templifyTemplates(); | ||
//... | ||
// ... | ||
``` | ||
Now when using angular later, the templates can be pulled from the $templateCache for use in unit and functional tests. | ||
Now when using angular later, the templates can be pulled from the $templateCache for use in unit and functional tests. | ||
For Example: | ||
```javascript | ||
describe("Templify Karma-Angular template processing", function() { | ||
var $compile, $scope; | ||
var template, html, element; | ||
__templifyTemplates(); | ||
describe("Templating", function() { | ||
beforeEach(inject(function(_$compile_, _$rootScope_) { | ||
$compile = _$compile_; | ||
$scope = _$rootScope_.$new(); | ||
})); | ||
it("passes standard checks", inject(function($templateCache) { | ||
$scope.title = "Titling"; | ||
$scope.paragraph = "This is some text"; | ||
template = $compile($templateCache.get("angular-template1.html"))($scope); | ||
$scope.$digest(); | ||
html = template.html(); | ||
expect(html).toContain($scope.title); | ||
expect(html).toContain($scope.paragraph); | ||
expect(html).not.toContain("title"); | ||
expect(html).not.toContain("paragraph"); | ||
})); | ||
}); | ||
}); | ||
``` |
@@ -7,5 +7,2 @@ | ||
// beforeEach(inject(function($templateCache) { | ||
// __templifyTemplates($templateCache); | ||
// })); | ||
__templifyTemplates(); | ||
@@ -12,0 +9,0 @@ |
19970
6.08%18
5.88%326
1.24%200
32.45%