angularjs - Testing Angular controller with Require and Typescript -
I am trying to create a basic test to verify that I can create an administrator or service
My app is the following directory
app / js / app.js
My controllers are in the following directory
ap / js / controller /
Here's my karma. Config.js file
files: ['scripts / jquery.2.1.1.min.js',' scripts / require.js', 'script / angular. JS ',' scripts / angular-mocks.js ', {pattern:' app / js / *. Js ', includes: wrong}, {pattern:' ap / js / ** / *. JS ', included: wrong}, {pattern:' app / js / ** / ** / *. JS ', included: Incorrect}, {Pattern:' AP / JS / ** / ** / ** / *. JS ', included: wrong}, {pattern:' test / specs / ** / *. JS ', included: Incorrect},' Exclude list of files to exclude / test-main.js',], // list: ['app / js / main.js'],
test-main.js
var testFiles = []; (.__ karma __ files in the var file) {console.log (file); If (/Spec\.js$/.test(file)) {testFiles.push (file); }} Requirejs.config ({path: {// external libraries' jquery ':' ../../Scripts/jquery-2.1.1.min ',' angular ':' ../../Scripts/angular ',' Angular-mask ':' ../../Scripts/angular-mocks ',' ngRoute ':' ../../Scripts/angular-route.min ',' angular-conscious ':'. ./../Scripts/angular-animate.min ',' angi-cookie ':' ../../Scripts/angular-cookies.min ',}, baseUrl:' / base / app / js', shim : {'Angular': {export: 'angular', deps: ['jquery']}, 'angular-mocks': {export:' angular-socks', deps: ['somebody']}, 'angled-animate 'Export:' angular-conscious', deps: ['angular']}, 'NGRURU': {Export: 'NGRUT', Deep: ['angular']}, 'angular-cookies': {Export: N Jiller-cookies', ['angular']}}, dynamically loads all test files: testFiles, // We have to start Jasmine because it is asynchronous callback: window .__ karma __.start} );
I added this line ...
console.log (file)
to make sure For that file was loaded in the
window. __Karma __ File
And it is.
Define test / specs /
(['angular', 'angular-socks'], (Connor, NGMock: ng. IMocetatic) => Var module = ngMock.module; var Inject: (... fns: function []) = & gt; any = ngMock.inject; description ("create an application", function () {var scope, queue, path params ; Var location; var app; first (function () {app = angular module ('app', []); injection (function ($ rootscope, $ q: ng.icuscurity, $ location: ng.lision services) {scope = $ RootScope; q = $ q; route Araj = {}; Location = $ Area;});}); ( 'test applications built', function () {define (true). TB (true);});});});
My app file looks like this ....
Import Angle = Required ('Angle'); Import angular route = requirement ('angular route'); Import angularity = essential ('angular-animate'); Requires import = ds = ('service / data service'); Var app = angular Modules ('Ape', ['NGRUT', 'NGMMAT', 'NGQQs', 'Kendo Dirivis', 'Hernangular', 'UI. Bootstrap']); Export = app;
When I try to run the test, I think
The module failed to instantify the app: the module 'app' is not available! You either misspelled the name of the module or forgot to load it.
I am assuming that this is not being loaded but I am not sure how I can tell. Is this the best way to complete my test?
Any help is greatly appreciated!
Thanks a lot!
If you are using Karma with Jasmine, you may have Jasmin having a lot of curiosity.
It can be fixed by two changes, originally described in an article when I did that.
boot.js you need to comment env.execute ();
Method Call:
window.onload = function () {if (currentWindowOnload) {currentWindowOnload (); } Htmlreperorter.initialize (); //env.execute (); };
The reason for this is that the window.onload
may be required before the event. JS has loaded everything.
Once you need to load the module, you can call:
// High Jasmin - ready to go! Jasmine.getEnv () executed () .;
Comments
Post a Comment