Loading luminaires with karma

File attribute in my configuration file for Karma

files: [ // Program files 'public/js/init.js', // Load mocks directly from bower 'bower_components/angular-mocks/angular-mocks.js', // Fixtures { pattern: 'test/fixtures/*.json', watched: true, served: true, included: false }, // Specs 'test/unit/**/*.spec.*' ] 

And one of the devices looks like this: test / fixtures / languages.json

 { "ab":{ "name":"Abkhaz", "nativeName":"ҧ" }, "aa":{ "name":"Afar", "nativeName":"Afaraf" }, "af":{ "name":"Afrikaans", "nativeName":"Afrikaans" } } 

How can I load the json mentioned above in a variable in a wait expression?

+4
source share
1 answer

You can do it manually with ajax, or you can use karma with requirejs and the jj loader plugin of the requirejs file ...

 var xhr = new XMLHttpRequest(); xhr.open('get', '/base/test/fixtures/languages.json', false); xhr.send(); console.log(xhr.status, xhr.responseText); //200, {...} 

Karma works in the browser, so you can do everything with karma, which you can usually do in the browser ... If you want to use the generated information from the server side, keep in mind that karma has its own server, so your tests are performed in different domains, and you must use CORS to retrieve data from your application server. For static files on the client side this should not cause problems if you register your templates in your karma configuration file ...

+1
source

Source: https://habr.com/ru/post/1499253/


All Articles