【问题标题】:Unit tests for Firebase - files not included issue (router 404 issue)Firebase 的单元测试 - 不包含文件的问题(路由器 404 问题)
【发布时间】:2016-03-06 23:14:01
【问题描述】:

firebase 的单元测试 - 文件未包含问题。 我无法运行单元测试。

测试代码看起来不错,但似乎缺少一些文件?

我在代码中使用 typescript 而不是基本的 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>

这是我在运行该测试时遇到的错误:

业力配置:

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

【问题讨论】:

  • 有人知道上面的错误是什么意思吗?

标签: javascript unit-testing typescript firebase angular


【解决方案1】:

我找到了答案。

我基本上有一个业力配置问题。

我设法通过更新 karma 配置文件中的模式来运行单元测试。

【讨论】:

  • 很高兴听到您解决了这个问题。您能否添加一些有关您在配置中修复的内容的更多信息(请注意,您的问题不包含任何业力配置),以便此答案对其有类似问题的其他人更有用?
  • 是的,我明天会为你添加它
  • 嗨弗兰克,我已经为你添加了上面的配置。
猜你喜欢
  • 2014-10-11
  • 2015-02-24
  • 2019-09-02
  • 2011-10-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多