2015-12-02 23 views
2

單元測試的firebase - 文件不包括問題。 我無法運行單元測試。單元測試的Firebase - 文件不包括問題(路由器404問題)

測試代碼似乎很好,但似乎有些文件丟失?

我使用打字稿,而不是基本的JavaScript爲我的代碼

這是我的測試:

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,()=>{ 

     }); 
    } 
} 

這是我目前的測試:

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(); 
    }) 

}); 

這是我的index.html文件(我認爲問題在這裏):

<!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> 

這是我得到的錯誤,當我運行測試:

enter image description here

噶配置:

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's 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's compiler 
    "/app/": "/base/src/app/" 
}, 

reporters: ['progress'], 
port: 9876, 
colors: true, 
logLevel: config.LOG_INFO, 
autoWatch: true, 
browsers: ['Chrome'], 
singleRun: false 
    }) 
} 
+0

有誰知道上面的錯誤是什麼意思? – AngularM

回答

1

我找到了答案是。

我基本上有一個karma配置問題。

我設法通過更新karma配置文件中的模式來運行單元測試。

+0

很高興聽到你已經解決了它。你可以添加一些關於你在配置中修復了什麼的信息(注意你的問題不包含任何karma配置),所以這個答案會對其他有類似問題的人更有用? –

+0

嗯確定我會爲你添加明天 – AngularM

+0

嗨,弗蘭克,我已經添加了上面的fr配置。 – AngularM