这是一个简化开发的问题,也是一个最佳实践问题.
<?php
class FOO implements Iterator
{
....
}
class BAR extends FOO
{
....
}
class OTHER extends FOO implements Iterator
{
....
}
?>
Run Code Online (Sandbox Code Playgroud)
在上面的例子中,BAR还有Iterator接口吗?如果是这样,每次无论如何定义界面(如OTHER)或将BAR定义视为最佳实践是否更好?
我简化了这个例子,因为我们正在使用FOO的抽象类,我们希望确保有Iterator支持,然后可以在BAR类中重写它以便在元素之间移动.我们希望强制为子类定义一些函数,但是想要继承其他方法,并且仍然使用基本迭代器,而不必在子类上定义接口.
我正在一个结构上运行一个示例 Jest 测试,我发现我的 Jest 输出摘要中的错误有几行。
包.json
"devDependencies": {
"@types/jest": "^22.0.1",
"jest": "^22.1.4",
"jest-preset-angular": "^5.0.0",
"ts-jest": "^22.0.1",
"typescript": "^2.6.2"
},
Run Code Online (Sandbox Code Playgroud)
输出:
Venue › Venue Structure › should have all the structure fields
expect(received).toBeDefined()
Expected value to be defined, instead received
undefined
20 | it('should be an instance of DataStructure', () => {
21 | expect(VenueInfo instanceof DataStructure).toBeTruthy();
> 22 | })
23 |
24 | it('should have the proper number of data fields', () => {
25 | expect(VenueInfo.NumberOfFields).toBe(14); // LastUpdated …Run Code Online (Sandbox Code Playgroud) 我有我的Gulp设置,可以在应用程序发生变化时自动加载/刷新我的网页.但是,我还想让它加载我的文档页面,并且每次都刷新该源文件.
我把它配置为从两个目录服务,但我不知道如何使用文档目录加载第二个选项卡.
[BS] Access URLs:
---------------------------------------
Local: http://localhost:3000
External: http://192.168.11.181:3000
---------------------------------------
UI: http://localhost:3001
UI External: http://192.168.11.181:3001
---------------------------------------
[BS] Serving files from: app/
[BS] Serving files from: docs/API.v1.1.0/
Run Code Online (Sandbox Code Playgroud)
我的gulpfile.js服务器部分.
AppSync.init({
server: {
baseDir: [RootDir.home, RootDir.docs + DocumentationPath.javascript],
index: 'index.html',
directory: false, // Set to True for Browsing Files, not launching index
},
//open: false,
//reloadOnRestart: false
});
Run Code Online (Sandbox Code Playgroud)
我尝试HelpSync使用BrowserSync.create()和设置服务器变量添加第二个,但是这给出了重新使用地址的错误,即使我指定了一个新端口.
我希望启动并加载我的App和API文档,并在更改任何代码时继续刷新.我可以验证应用程序的工作原理,并且我的API确实正确记录了文档.
针对基本软件包运行Jest时,在运行测试时出现Jest错误,仅在运行时不会出现ionic serve。笑话上出现错误
import { Platform } from '@ionic/angular';
Run Code Online (Sandbox Code Playgroud)
这是:
export { IonicModule } from './ionic-module';
^^^^^^
SyntaxError: Unexpected token export
3 | import { RouterTestingModule } from '@angular/router/testing';
4 |
> 5 | import { Platform } from '@ionic/angular';
| ^
6 | import { SplashScreen } from '@ionic-native/splash-screen/ngx';
7 | import { StatusBar } from '@ionic-native/status-bar/ngx';
8 |
at ScriptTransformer._transformAndBuildScript (node_modules/jest-runtime/build/script_transformer.js:403:17)
at Object.<anonymous> (src/app/app.component.spec.ts:5:1)
Run Code Online (Sandbox Code Playgroud)
我的Jest.config.json
module.exports = {
collectCoverage: true,
collectCoverageFrom: [
"src/**/*.ts"
],
coverageDirectory: "<rootDir>/coverage/",
moduleNameMapper: …Run Code Online (Sandbox Code Playgroud) 我正在开玩笑地运行我的测试套件(后端为Node.js和express)。下面是我的代码:
Const puppeteer = require ('puppeteer');
Test ('testing login function', async () => {
const browser = await puppeteer.launch ({
headless: true,
args: ['--no-sandbox']
});
const page = await browser.newPage();
await page.type('#username', 'admin');
await page.type('#password', 'password');
await page.click('login-button');
await page.waitFor('.card');
expect(texthead).toEqual('Welcome to webpage');
await browser.close();
});
Run Code Online (Sandbox Code Playgroud)
我试图一次运行同一测试多次,是否有jestjs使用它的方法,或者也许使用其他工具。
我正在尝试使用 Express 并解析 XML 正文。我将 bodyparser 用于文本,但无法让 xml2js 将我的 XML 解析为可用格式。
import * as xml2js from 'xml2js';
try {
const XML:string = '<Pan>0000000000000702203</Pan>';
xml2js.parseString(XML, {trim: true}, function (err, result) {
if(err) console.log(err);
console.log(result);
});
} catch (e) {
console.log(e);
}
Run Code Online (Sandbox Code Playgroud)
要么不起作用:
try {
xml2js.parseString(XML, {trim: true}, (err, result) => {
if(err) console.log(err);
console.log(result);
});
} catch (e) {
console.log(e);
}
Run Code Online (Sandbox Code Playgroud)
在 VSCode 调试器中运行它时,代码会立即跳过该函数并且不处理 xml2js.parseString()。错误和结果永远不会得到值。
我也尝试过使用 Parser() 类:
const p:xml2js.Parser = new xml2js.Parser();
p.parseString(XML, (err:{}, result:{}) => {
if(err) console.log(err);
console.log(result); …Run Code Online (Sandbox Code Playgroud) 我有一个简单的类,我试图使用 NestJS 和端到端测试来确保我可以使验证正常工作,但我无法使验证工作。如果我使用 Postman 或普通客户端发送数据,应用程序确实会响应正确的错误。
API.dto.ts
import { IsNumber, IsPositive, IsString } from 'class-validator';
export class ApiDTO {
@IsString() public readonly FileName:string;
@IsNumber() @IsPositive() public readonly StatusCode:number;
@IsNumber() @IsPositive() public readonly TimeOut:number;
}
Run Code Online (Sandbox Code Playgroud)
端到端测试文件
import { Test, TestingModule } from '@nestjs/testing';
import * as request from 'supertest';
import { INestApplication, ValidationPipe } from '@nestjs/common';
import { AppModule } from '@APP/app.module';
import { ApiDTO } from './../../src/api/api.dto';
describe('ApiController (e2e)', () => {
let app: INestApplication;
beforeEach(async () => {
const moduleFixture: …Run Code Online (Sandbox Code Playgroud) 我一直在按照教程尝试让 Typescript 与 Angular 2 一起工作。问题是我似乎无法编译子目录并保留子目录。
我的 tsconfig.json
{
"compilerOptions": {
"target": "ES5",
"module": "commonjs",
"outDir": "build",
"sourceMap": true,
"sourceRoot": "src",
"experimentalDecorators": true,
"noEmitOnError": true,
"noImplicitAny": true,
"removeComments": false
},
"exclude": [
"build",
"client",
"GulpTasks",
"node_modules",
"typings"
]
}
Run Code Online (Sandbox Code Playgroud)
现在我的源代码有不同的模块和项目的客户端/服务器文件夹。
+build
+node_modules
+src
---+client
---+dir1
---+file1.ts
---+dir2
---+server
---+file1.ts
+typings
Run Code Online (Sandbox Code Playgroud)
编译时我需要保留目录结构,但是在子目录 (src/server) 中找到的文件在移入构建文件夹时不会保留服务器子目录文件夹。没有 build/server/file1.js,但它只是 build/file1.js。
写JS文件时,如何配置tsc移动子目录下的文件?我在 src/client/dir1 中有一些文件与 server/dir1 文件同名,并且不能覆盖另一个。
我正在尝试测试我编写的库函数(它在我的代码中工作),但无法使用 fs 的模拟进行测试。我有一系列用于处理封装在函数中的操作系统的函数,因此应用程序的不同部分可以使用相同的调用。
我试图通过模拟文件系统来解决这个问题,但它似乎对我不起作用。
演示我的问题的基础知识的简短示例如下:
import * as fs from 'fs';
export function ReadFileContentsSync(PathAndFileName:string):string {
if (PathAndFileName === undefined || PathAndFileName === null || PathAndFileName.length === 0) {
throw new Error('Need a Path and File');
}
return fs.readFileSync(PathAndFileName).toString();
}
Run Code Online (Sandbox Code Playgroud)
所以现在我正在尝试使用 Jest 测试这个函数:
import { ReadFileContentsSync } from "./read-file-contents-sync";
const fs = require('fs');
describe('Return Mock data to test the function', () => {
it('should return the test data', () => {
const TestData:string = 'This is sample Test Data'; …Run Code Online (Sandbox Code Playgroud) 我在Firebase中有不同的部分和规范化数据,我有例程来获取信息,但我不能遍历返回的记录来获取数据.我想使用$ firebaseArray()中的键从其他$ firebaseObject()中获取数据.
GetOneTeam() .... {
var DataRef = GetFireBaseObject.DataURL(Node + '/'); // xxx.firebaseio.com/Schedules/
var OneRecordRef = DataRef.child(Key); // Schedule Key - 1
return $firebaseObject(OneRecordRef);
}
...
var Sched = GetOneSchedule('Schedules', 1);
... // For Loop getting data - Put in HomeId
var TeamRec = GetOneTeam('Teams', HomeId);
var Name = TeamRec.TeamName; // Does not TeamName value from Schedule/1
Run Code Online (Sandbox Code Playgroud)
如果上面的代码段不够清楚,以下是更多的实际代码.获取数据的常用例程示例:
angular.module('MyApp')
.constant('FIREBASE_URL', 'https://xxxxxxxx.firebaseio.com/');
angular.module('MyApp')
.factory('GetFireBaseObject', function(FIREBASE_URL) {
return {
BaseURL: function() {
return new Firebase(FIREBASE_URL);
},
DataURL: function(Node) {
return new …Run Code Online (Sandbox Code Playgroud) jestjs ×5
typescript ×4
angular ×1
angularfire ×1
angularjs ×1
browser-sync ×1
firebase ×1
gulp ×1
inheritance ×1
ionic-native ×1
ionic4 ×1
mocking ×1
nestjs ×1
node.js ×1
oop ×1
php ×1
testing ×1
xml ×1
xml2js ×1