Converts json to AngularJS modules for test fixtures
npm install grunt-ng-json2js~0.4.5
shell
npm install grunt-ng-json2js --save-dev
`
Once the plugin has been installed, it may be enabled inside your Gruntfile with this line of JavaScript:
`js
grunt.loadNpmTasks('grunt-ng-json2js');
`
The "ng_json2js" task
$3
In your project's Gruntfile, add a section named ng_json2js to the data object passed into grunt.initConfig().
`js
grunt.initConfig({
ng_json2js: {
options: {
// strip this from the file path
stripPrefix: 'test/fixture/',
// prepend this to the
prependPrefix: 'served/'
},
files: [
'/testData/*/.json'
],
},
});
`
Examples
For instance this test/fixture/data.json ...
`json
{
prop: val
}
`
... with the configuration given above will be converted into:
`js
angular.module('served/data.json', []).value('servedData', {
prop: 'val'
});
`
Inject json fixture into your test case:
`js
describe('me', function(){
beforeEach(module('served/data.json'));
it('should not fail', function() {
var testFixture;
inject(function (_servedData_) {
testFixture = _servedData_;
});
expect(testFixture).toEqual({
prop: 'val'
});
});
});
``