gpt4 book ai didi

javascript - Firebase 的单元测试 - 文件未包含问题(路由器 404 问题)

转载 作者:搜寻专家 更新时间:2023-10-30 21:53:50 25 4
gpt4 key购买 nike

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>

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

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

最佳答案

我找到了答案。

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

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

关于javascript - Firebase 的单元测试 - 文件未包含问题(路由器 404 问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34047379/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com