Unit tests for Firebase - files not included in the problem (404 router release)

Unit tests for firebase - files not included. I am having trouble running unit test.

The test code seems fine, but it seems some files are missing?

I use typescript instead of basic JavaScript for my code

This is what I am testing:

export class AppComponent { ref: Firebase; refUsers: Firebase; refProfiles: Firebase; constructor(){ this.ref = new Firebase("https://markng2.firebaseio.com"); this.refUsers = new Firebase("https://markng2.firebaseio.com/users"); this.refProfiles = new Firebase("https://markng2.firebaseio.com/profiles"); } public addUser(newUser: Object): void{ this.refUsers.push(newUser, ()=>{ }); } } 

This is my current test:

  import {it, iit, describe, expect, inject, injectAsync, beforeEachProviders, fakeAsync, tick } from 'angular2/testing'; import { AppComponent } from '../app/app'; describe('AppComponent', () => { it('saves an item to Firebase', () => { let refUsers = new Firebase(''); let service = new AppComponent(); spyOn(service.refUsers, 'push'); service.addUser({ item: true }); expect(service.refUsers.push).toHaveBeenCalled(); }) }); 

This is my index.html file (I think the problem is here):

  <!DOCTYPE html> <html> <head> <base href="/"></base> <title>Angular2</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous"> <script src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.src.js"></script> <script> System.config({ transpiler: 'typescript', defaultJSExtensions: true }); </script> <script src="angular2.dev.js"></script> <script src="router.dev.js"></script> <script src="http.js"></script> <script src="firebase/firebase.js"></script> </head> <body class="container"> <app></app> <script> System.import('app/app'); </script> </body> </html> = "sha512-K1qjQ + NcF2TYO / eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG + aHRqLi / ETn2uB + 1JqwYqVG3LIvdm9lj6imS / pQ =="  <!DOCTYPE html> <html> <head> <base href="/"></base> <title>Angular2</title> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap-theme.min.css" integrity="sha384-aUGj/X2zp5rLCbBxumKTCw2Z50WgIr1vs/PFN4praOTvYXWlVyh2UtNUU0KAUhAX" crossorigin="anonymous"> <script src="//code.jquery.com/jquery-1.11.3.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.src.js"></script> <script> System.config({ transpiler: 'typescript', defaultJSExtensions: true }); </script> <script src="angular2.dev.js"></script> <script src="router.dev.js"></script> <script src="http.js"></script> <script src="firebase/firebase.js"></script> </head> <body class="container"> <app></app> <script> System.import('app/app'); </script> </body> </html> 

This is the error I get when doing this test:

enter image description here

Karma configuration:

  module.exports = function(config) { config.set({ basePath: '', frameworks: ['jasmine'], files: [ // paths loaded by Karma {pattern: 'node_modules/systemjs/dist/system.src.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/angular2.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/testing.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/router.dev.js', included: true, watched: true}, {pattern: 'node_modules/angular2/bundles/http.js', included: true, watched: true}, {pattern: 'src/firebase/firebase.js', included: true, watched: true}, {pattern: 'karma-test-shim.js', included: true, watched: true}, // paths loaded via module imports {pattern: 'src/**/*.js', included: false, watched: true}, // paths loaded via Angular component compiler // (these paths need to be rewritten, see proxies section) {pattern: 'src/**/*.html', included: false, watched: true}, {pattern: 'src/**/*.css', included: false, watched: true}, // paths to support debugging with source maps in dev tools {pattern: 'src/**/*.ts', included: false, watched: false}, {pattern: 'src/**/*.js.map', included: false, watched: false} ], // proxied base paths proxies: { // required for component assests fetched by Angular compiler "/app/": "/base/src/app/" }, reporters: ['progress'], port: 9876, colors: true, logLevel: config.LOG_INFO, autoWatch: true, browsers: ['Chrome'], singleRun: false }) } 
+2
source share
1 answer

I have found the answer.

I have a problem with karma configuration basically.

I managed to run unit tests by updating the templates in the karma configuration files.

+1
source

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


All Articles