├── .editorconfig ├── .eslintignore ├── .eslintrc ├── .gitignore ├── .nvmrc ├── .travis.yml ├── LICENSE ├── README.md ├── angular-xml.js ├── angular-xml.min.js ├── bower.json ├── git-hooks └── pre-commit.sh ├── index.js ├── package-lock.json ├── package.json └── test ├── .eslintrc ├── e2e.conf.js ├── e2e.travis.conf.js ├── e2e ├── emptySpec.html ├── xmlSpec.html ├── xmlSpec.js └── xmlSpec.xml ├── server.js ├── unit.conf.js └── unit └── xmlSpec.js /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig is awesome: http://EditorConfig.org 2 | 3 | # top-most EditorConfig file 4 | root = true 5 | 6 | # Unix-style newlines with a newline ending every file 7 | [*] 8 | end_of_line = lf 9 | insert_final_newline = true 10 | 11 | # Matches multiple files with brace expansion notation 12 | # Set default charset 13 | [*] 14 | charset = utf-8 15 | # Indentation override for all JS under lib directory 16 | indent_style = space 17 | indent_size = 2 18 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | bower_components 2 | coverage 3 | *.min.js 4 | node_modules 5 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": [ 4 | 1, 5 | 2 6 | ], 7 | "quotes": [ 8 | 1, 9 | "single" 10 | ], 11 | "linebreak-style": [ 12 | 2, 13 | "unix" 14 | ], 15 | "semi": [ 16 | 1, 17 | "always" 18 | ], 19 | "camelcase": 0, 20 | "no-shadow": 0 21 | }, 22 | "env": { 23 | "browser": true 24 | }, 25 | "globals": { 26 | "angular": false, 27 | "X2JS": false 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.log 2 | *.swp 3 | bower_components 4 | components 5 | coverage 6 | node_modules 7 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | lts/* 2 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | addons: 4 | sauce_connect: true 5 | 6 | before_install: 7 | - '[[ $(node -v) =~ ^v9.*$ ]] || npm install -g npm@latest' 8 | 9 | install: 10 | - npm ci || npm install 11 | 12 | before_script: 13 | - npx bower i 14 | - npm run update-webdriver 15 | - export DISPLAY=:99.0 16 | - sh -e /etc/init.d/xvfb start 17 | - sleep 3 18 | 19 | script: 20 | - npm run test-travis 21 | 22 | after_script: 23 | - npx -p greenkeeper-lockfile greenkeeper-lockfile-upload 24 | 25 | after_success: 26 | - bash <(curl -s https://codecov.io/bash) 27 | 28 | notifications: 29 | email: false 30 | 31 | env: 32 | global: 33 | secure: rjXS5iQeUkdesaW1RUtTur1ulNhZfhfOF2dlTyG14my80GdAT0g+kmIa2xZI6pB16Im+WJGO4CTzzzHOSetw+shnCHrccz5CTDTMINE1j9hTqP40rAkHDMPA1pOt3fmFbQ5cZxGLtu6BaDkL2Z6mSvQ7exIzMdFmTG36l9lXPGc= 34 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2013-2018 John Wright http://j-g-w.info 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [X2JS]: https://code.google.com/p/x2js/ 2 | 3 | [![Codecov](https://img.shields.io/codecov/c/github/johngeorgewright/angular-xml/master.svg?style=flat-square)](https://codecov.io/gh/johngeorgewright/angular-xml) 4 | [![Build Status](https://img.shields.io/travis/johngeorgewright/angular-xml/master.svg?style=flat-square)](https://travis-ci.org/johngeorgewright/angular-xml) 5 | [![NPM Version](https://img.shields.io/npm/v/angular-xml.svg?style=flat-square)](https://www.npmjs.com/package/angular-xml) 6 | [![Bower](https://img.shields.io/bower/v/angular-xml.svg)](https://libraries.io/bower/angular-xml) 7 | [![Dependencies](https://img.shields.io/gemnasium/johngeorgewright/angular-xml.svg?style=flat-square)](https://gemnasium.com/github.com/johngeorgewright/angular-xml) 8 | [![License](https://img.shields.io/npm/l/angular-xml.svg?style=flat-square)](https://github.com/johngeorgewright/angular-xml/blob/master/LICENSE) 9 | [![Greenkeeper badge](https://badges.greenkeeper.io/johngeorgewright/angular-xml.svg)](https://greenkeeper.io/) 10 | 11 | [![Sauce Test Status](https://saucelabs.com/browser-matrix/angular-xml.svg)](https://saucelabs.com/u/angular-xml) 12 | 13 | 14 | angular-xml 15 | =========== 16 | 17 | > XML module for AngularJS. 18 | 19 | **As of v2.0.0 this module relies on the X2JS module** 20 | 21 | Supplies the [X2JS][] library as a service and provides a HTTP interceptor to convert all XML responses in to JSON. 22 | 23 | Configuring the X2JS service 24 | ---------------------------- 25 | 26 | ```js 27 | angular 28 | .module('myMod', ['xml']) 29 | .config(function (x2jsProvider) { 30 | x2jsProvider.config = { 31 | /* 32 | escapeMode : true|false - Escaping XML characters. Default is true from v1.1.0+ 33 | attributePrefix : "" - Prefix for XML attributes in JSon model. Default is "_" 34 | arrayAccessForm : "none"|"property" - The array access form (none|property). Use this property if you want X2JS generates an additional property _asArray to access in array form for any XML element. Default is none from v1.1.0+ 35 | emptyNodeForm : "text"|"object" - Handling empty nodes (text|object) mode. When X2JS found empty node like it will be transformed to test : '' for 'text' mode, or to Object for 'object' mode. Default is 'text' 36 | enableToStringFunc : true|false - Enable/disable an auxiliary function in generated JSON objects to print text nodes with text/cdata. Default is true 37 | arrayAccessFormPaths : [] - Array access paths. Use this option to configure paths to XML elements always in "array form". You can configure beforehand paths to all your array elements based on XSD or your knowledge. Every path could be a simple string (like 'parent.child1.child2'), a regex (like /.*\.child2/), or a custom function. Default is empty 38 | skipEmptyTextNodesForObj : true|false - Skip empty text tags for nodes with children. Default is true. 39 | stripWhitespaces : true|false - Strip whitespaces (trimming text nodes). Default is true. 40 | datetimeAccessFormPaths : [] - Datetime access paths. Use this option to configure paths to XML elements for "datetime form". You can configure beforehand paths to all your array elements based on XSD or your knowledge. Every path could be a simple string (like 'parent.child1.child2'), a regex (like /.*\.child2/), or a custom function. Default is empty 41 | */ 42 | }; 43 | }); 44 | ``` 45 | 46 | For any more information on how to configure and use the X2JS service, [see their project][X2JS]. 47 | 48 | Accessing the X2JS service 49 | -------------------------- 50 | 51 | ```js 52 | angular 53 | .module('myMod', ['xml']) 54 | .factory('someFactory', function (x2js) { 55 | var xmlDoc = x2js.json2xml( 56 | { 57 | MyRoot : { 58 | MyChild : 'my_child_value', 59 | MyAnotherChild: 10, 60 | MyArray : [ 'test', 'test2' ], 61 | MyArrayRecords : [ 62 | { 63 | ttt : 'vvvv' 64 | }, 65 | { 66 | ttt : 'vvvv2' 67 | } 68 | ] 69 | } 70 | } 71 | ); 72 | }); 73 | ``` 74 | 75 | [Read the docs][X2JS] on how to use it. 76 | 77 | Using the HTTP interceptor 78 | -------------------------- 79 | 80 | The HTTP interceptor will convert all your XML responses in to a JavaScript Object. 81 | 82 | ```xml 83 | 84 | 85 | 86 | 87 | ``` 88 | 89 | ```js 90 | // blogs.js 91 | angular 92 | .module('blogs', ['xml']) 93 | .config(function ($httpProvider) { 94 | $httpProvider.interceptors.push('xmlHttpInterceptor'); 95 | }) 96 | .controller(function ($scope, $http) { 97 | $http.get('blogs.xml').success(function (data) { 98 | $scope.blogs = data.blogs.blog; 99 | }); 100 | }); 101 | ``` 102 | 103 | ```html 104 | 105 | 106 | 107 | Blogs 108 | 109 | 110 | 111 | 112 | 113 | 114 | 119 | 120 | 121 | ``` 122 | 123 | Installation 124 | ------------ 125 | 126 | First acquire the [X2JS][] library (this comes bundled with the bower option described next) 127 | 128 | Then there are 3 optoins: 129 | 130 | 1. Download the latest tag. 131 | 2. Use bower: `bower i --save angular-xml` 132 | 3. Or use jsDelivr CDN: `//cdn.jsdelivr.net/npm/angular-xml@2.2.2/angular-xml.min.js` 133 | 134 | Contributing 135 | ------------ 136 | 137 | To contribute to the project take the following steps: 138 | 139 | 1. [Fork](https://github.com/johngeorgewright/angular-xml/fork) the project. 140 | 2. Create a [branch](http://git-scm.com/docs/git-branch) specific for your change(s). 141 | 3. Submit a [pull request](https://help.github.com/articles/using-pull-requests/) to my master branch and we can begin the process of merging. 142 | 143 | *When submitting, please make sure your code is covered by tests.* 144 | 145 | ### Tests 146 | 147 | The unit tests run with [Karma](http://karma-runner.github.io/0.12/index.html) and the E2E tests run with [Protractor](https://github.com/angular/protractor). 148 | 149 | #### Update the webdriver 150 | 151 | ``` 152 | npm run update-webdriver 153 | ``` 154 | 155 | #### Run the test suite 156 | 157 | ``` 158 | npm test 159 | ``` 160 | 161 | Or, to watch your files and test automatically: 162 | 163 | ``` 164 | npm run dev 165 | ``` 166 | 167 | ### Compiling 168 | 169 | The source file `angular-xml.js` can be minifed and checked for problems using a grunt command. First make sure you have installed all npm dependencies `npm i`. Then run `grunt`. 170 | 171 | [angular.element]: http://docs.angularjs.org/api/angular.element 172 | 173 | ### Git Hooks 174 | 175 | There is a git hook available for shell environments that will automatically lint, test and compile the xml module when commiting it. To use it simply link it in to the git hook directory. 176 | 177 | ``` 178 | npm run hook-git 179 | 180 | # And... of you want to remove the hook 181 | npm run unhook-git 182 | ``` 183 | 184 | Now when you change the `angular-xml.js` file and commit it, it will be linted, tested and if all is OK, then compiled and the minified version wil be added to your commit. 185 | -------------------------------------------------------------------------------- /angular-xml.js: -------------------------------------------------------------------------------- 1 | if (!X2JS) { 2 | throw new Error('You\'re required to include the X2JS library to use the xml module.'); 3 | } 4 | 5 | (function(ng, X2JS) { 6 | 'use strict'; 7 | 8 | function responseIsXml(response) { 9 | var contentType = response.headers('content-type'); 10 | if (contentType) { 11 | return contentType.search(/\Wxml/i) > -1; 12 | } else { 13 | return false; 14 | } 15 | } 16 | 17 | function xmlHttpInterceptorFactory($q, x2js) { 18 | function responseHandler(response) { 19 | if (response && responseIsXml(response)) { 20 | response.data = x2js.xml_str2json(response.data); 21 | return response; 22 | } else { 23 | return $q.when(response); 24 | } 25 | } 26 | function responseErrorHandler(response) { 27 | if (response && responseIsXml(response)) { 28 | response.data = x2js.xml_str2json(response.data); 29 | } 30 | return $q.reject(response); 31 | } 32 | return { 33 | response: responseHandler, 34 | responseError: responseErrorHandler 35 | }; 36 | } 37 | 38 | function configProvider($provide) { 39 | $provide.factory('xmlHttpInterceptor', ['$q', 'x2js', xmlHttpInterceptorFactory]); 40 | } 41 | 42 | function X2JSProvider() { 43 | this.config = {}; 44 | this.$get = ['X2JS', function (X2JS) { 45 | return new X2JS(this.config); 46 | }]; 47 | } 48 | 49 | if (ng) { 50 | ng 51 | .module('xml', []) 52 | .config(['$provide', configProvider]) 53 | .provider('x2js', X2JSProvider) 54 | .value('X2JS', X2JS); 55 | } 56 | 57 | }(angular, X2JS)); 58 | -------------------------------------------------------------------------------- /angular-xml.min.js: -------------------------------------------------------------------------------- 1 | if(!X2JS)throw Error("You're required to include the X2JS library to use the xml module."); 2 | (function(c,e){function d(b){return(b=b.headers("content-type"))?-1 angular-xml.min.js", 42 | "update-webdriver": "webdriver-manager update", 43 | "hook-git": "ln -s ../../git-hooks/pre-commit.sh .git/hooks/pre-commit", 44 | "unhook-git": "rm .git/hooks/pre-commit" 45 | }, 46 | "repository": { 47 | "type": "git", 48 | "url": "git://github.com/johngeorgewright/angular-xml.git" 49 | }, 50 | "keywords": [ 51 | "angular", 52 | "xml" 53 | ], 54 | "author": "John Wright ", 55 | "license": "BSD", 56 | "readmeFilename": "README.md", 57 | "gitHead": "818239745e3953f67761b27a17ac7c43a23ee690", 58 | "bugs": { 59 | "url": "https://github.com/johngeorgewright/angular-xml/issues" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": [ 4 | 1, 5 | 2 6 | ], 7 | "quotes": [ 8 | 1, 9 | "single" 10 | ], 11 | "linebreak-style": [ 12 | 2, 13 | "unix" 14 | ], 15 | "semi": [ 16 | 1, 17 | "always" 18 | ], 19 | "camelcase": 0 20 | }, 21 | "env": { 22 | "browser": true, 23 | "jasmine": true 24 | }, 25 | "globals": { 26 | "angular": false, 27 | "browser": false, 28 | "by": false, 29 | "element": false, 30 | "inject": false, 31 | "module": false, 32 | "X2JS": false 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/e2e.conf.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | 3 | // An example configuration file. 4 | exports.config = { 5 | directConnect: true, 6 | specs: ['e2e/**/*Spec.js'], 7 | baseUrl: 'http://localhost:8000' 8 | }; 9 | -------------------------------------------------------------------------------- /test/e2e.travis.conf.js: -------------------------------------------------------------------------------- 1 | /* global exports */ 2 | 3 | // An example configuration file. 4 | exports.config = { 5 | specs: ['e2e/**/*Spec.js'], 6 | baseUrl: 'http://localhost:8000', 7 | sauceUser: process.env.SAUCE_USERNAME, 8 | sauceKey: process.env.SAUCE_ACCESS_KEY, 9 | multiCapabilities: [{ 10 | browserName: 'chrome', 11 | 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER 12 | }, { 13 | browserName: 'firefox', 14 | 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER 15 | }, { 16 | browserName: 'internet explorer', 17 | 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER 18 | // }, { 19 | // browserName: 'safari', 20 | // 'tunnel-identifier': process.env.TRAVIS_JOB_NUMBER 21 | }] 22 | }; 23 | -------------------------------------------------------------------------------- /test/e2e/emptySpec.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | XML e2e testing 5 | 6 | 7 |

login required for {{title}}

8 |
    9 |
  • {{blog._id}} - {{blog._name}}
  • 10 |
11 | 12 | 13 | 14 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /test/e2e/xmlSpec.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | XML e2e testing 5 | 6 | 7 |

login required for {{title}}

8 |
    9 |
  • {{blog._id}} - {{blog._name}}
  • 10 |
11 | 12 | 13 | 14 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /test/e2e/xmlSpec.js: -------------------------------------------------------------------------------- 1 | describe('x2js', function () { 2 | 'use strict'; 3 | 4 | beforeEach(function () { 5 | browser.get('/test/e2e/xmlSpec.html'); 6 | }); 7 | 8 | it('will render 2 blogs', function () { 9 | expect(element.all(by.repeater('blog in blogs')).count()).toBe(2); 10 | }); 11 | 12 | it('display configuration title', function () { 13 | expect(element(by.binding('title')).getText()).toEqual('login required for myapp'); 14 | }); 15 | 16 | }); 17 | -------------------------------------------------------------------------------- /test/e2e/xmlSpec.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /test/server.js: -------------------------------------------------------------------------------- 1 | var express = require('express'); 2 | var pathHelper = require('path'); 3 | var server = express(); 4 | 5 | server.get('/401', function (req, res) { 6 | res.status(401); 7 | res.set('Content-Type', 'application/xml'); 8 | res.send('myapp'); 9 | }); 10 | 11 | server.use(express.static(pathHelper.resolve(__dirname, '..'))); 12 | 13 | server.listen(8000); 14 | 15 | process.on('SIGTERM', function () { 16 | process.exit(0); 17 | }); 18 | -------------------------------------------------------------------------------- /test/unit.conf.js: -------------------------------------------------------------------------------- 1 | /*eslint-env node*/ 2 | 3 | module.exports = function (config) { 4 | 'use strict'; 5 | 6 | config.set({ 7 | 8 | basePath: '..', 9 | 10 | frameworks: ['jasmine'], 11 | 12 | files: [ 13 | 'bower_components/angular/angular.js', 14 | 'bower_components/angular-mocks/angular-mocks.js', 15 | 'bower_components/x2js/xml2json.js', 16 | 'angular-xml.js', 17 | 'test/unit/**/*Spec.js' 18 | ], 19 | 20 | exclude: [ 21 | '**/*.swp' 22 | ], 23 | 24 | preprocessors: { 25 | 'angular-xml.js': 'coverage' 26 | }, 27 | 28 | // test results reporter to use 29 | // possible values: 'dots', 'progress', 'junit' 30 | reporters: ['progress', 'coverage'], 31 | 32 | coverageReporter: { 33 | type : 'lcovonly', 34 | dir : 'coverage/' 35 | }, 36 | 37 | // web server port 38 | port: 9876, 39 | 40 | 41 | // cli runner port 42 | runnerPort: 9100, 43 | 44 | 45 | // enable / disable colors in the output (reporters and logs) 46 | colors: true, 47 | 48 | 49 | // level of logging 50 | // possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG 51 | logLevel: config.LOG_INFO, 52 | 53 | 54 | // enable / disable watching file and executing tests whenever any file changes 55 | autoWatch: true, 56 | 57 | 58 | // Start these browsers, currently available: 59 | // - Chrome 60 | // - ChromeCanary 61 | // - Firefox 62 | // - Opera 63 | // - Safari (only Mac) 64 | // - PhantomJS 65 | // - IE (only Windows) 66 | browsers: ['Chrome'], 67 | 68 | 69 | // If browser does not capture in given timeout [ms], kill it 70 | captureTimeout: 60000, 71 | 72 | 73 | // Continuous Integration mode 74 | // if true, it capture browsers, run tests and exit 75 | singleRun: false 76 | 77 | }); 78 | 79 | }; 80 | -------------------------------------------------------------------------------- /test/unit/xmlSpec.js: -------------------------------------------------------------------------------- 1 | describe('xml', function () { 2 | 'use strict'; 3 | 4 | var xmlString = ''; 5 | 6 | beforeEach(module('xml')); 7 | 8 | describe('x2js', function () { 9 | it('will be an instance of X2JS', inject(function (x2js) { 10 | expect(x2js instanceof X2JS).toBe(true); 11 | })); 12 | }); 13 | 14 | describe('x2jsProvider', function () { 15 | var X2JS, config; 16 | 17 | beforeEach(module(function ($provide, x2jsProvider) { 18 | X2JS = jasmine.createSpy('X2JS'); 19 | config = {mung: 'face'}; 20 | x2jsProvider.config = config; 21 | $provide.value('X2JS', X2JS); 22 | })); 23 | 24 | it('will pass any configurations to the X2JS constructor', inject(function (x2js) { 25 | expect(x2js).not.toBeUndefined(); 26 | expect(X2JS).toHaveBeenCalledWith(config); 27 | })); 28 | }); 29 | 30 | describe('httpInterceptor', function () { 31 | var responseHeaders, x2js, $xmlHttpInterceptor; 32 | 33 | beforeEach(module(function ($provide) { 34 | responseHeaders = jasmine.createSpy('response.headers').and.returnValue('application/xml'); 35 | x2js = { 36 | xml_str2json: jasmine.createSpy('xxml_str2json') 37 | }; 38 | $provide.value('x2js', x2js); 39 | })); 40 | 41 | beforeEach(inject(function (xmlHttpInterceptor) { 42 | $xmlHttpInterceptor = xmlHttpInterceptor; 43 | })); 44 | 45 | function respond() { 46 | $xmlHttpInterceptor.response({ 47 | data: xmlString, 48 | headers: responseHeaders 49 | }); 50 | } 51 | 52 | function respondWithError() { 53 | $xmlHttpInterceptor.responseError({ 54 | data: xmlString, 55 | headers: responseHeaders 56 | }); 57 | } 58 | 59 | it('will check for the content-type', function () { 60 | respond(); 61 | expect(responseHeaders).toHaveBeenCalledWith('content-type'); 62 | }); 63 | 64 | it('will return a ng.element object', function () { 65 | respond(); 66 | expect(x2js.xml_str2json).toHaveBeenCalled(); 67 | }); 68 | 69 | it('will also work with the text/xml content-type', function () { 70 | responseHeaders.and.returnValue('text/xml'); 71 | respond(); 72 | expect(x2js.xml_str2json).toHaveBeenCalled(); 73 | }); 74 | 75 | it('will also work when then content-type has extra parameters', function () { 76 | responseHeaders.and.returnValue('application/xml, charset=UTF-8'); 77 | respond(); 78 | expect(x2js.xml_str2json).toHaveBeenCalled(); 79 | }); 80 | 81 | it('will work with engine generated rss feeds, with alternate response headers', function () { 82 | responseHeaders.and.returnValue('application/rss+xml'); 83 | respond(); 84 | expect(x2js.xml_str2json).toHaveBeenCalled(); 85 | }); 86 | 87 | it('will only act on a XML response', function () { 88 | responseHeaders.and.returnValue('text/html'); 89 | respond(); 90 | expect(x2js.xml_str2json).not.toHaveBeenCalled(); 91 | }); 92 | 93 | it('will only act on a response with a content-type', function () { 94 | responseHeaders.and.returnValue(null); 95 | respond(); 96 | expect(x2js.xml_str2json).not.toHaveBeenCalled(); 97 | }); 98 | 99 | it('will also convert error responses', function () { 100 | responseHeaders.and.returnValue('application/xml'); 101 | respondWithError(); 102 | expect(x2js.xml_str2json).toHaveBeenCalled(); 103 | }); 104 | }); 105 | }); 106 | --------------------------------------------------------------------------------