import { Headers, Http } from '@angular/http';
@Injectable()
export class PublisherService{
private publishersUrl = 'app/publisher';
constructor(private http: Http) { }
getPublishers(): Promise<Publisher[]>{
return this.http.get(this.publishersUrl)
.toPromise()
.then(response => response.json().data)
.catch(this.handleError);
}
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
属性'toPromise'在'Observable'类型上不存在
我正在尝试测试 HTTP 调用并参考以下页面来编写单元测试:https://angular-2-training-book.rangle.io/handout/testing/services/mockbackend.html
但是当我查看 Angular 网站时,该类似乎MockBackend已被弃用:https://angular.io/api/http/testing/MockBackend
同一网站有不同的方法来测试 HTTP 调用:https://angular-2-training-book.rangle.io/handout/testing/services/alt-http-mocking.html
我还发现了下面一篇有趣的文章(因为我正在尝试测试登录,因此进行 POST 调用):http://jasonwatmore.com/post/2016/11/24/angular-2-mockbackend-example-for-backendless -发展
所以我想知道测试 HTTP 调用的最佳或最新方法是什么?我有点困惑是否使用MockBackend或使用spyOn模拟策略。
unit-testing angular2-services angular2-http angular2-testing angular
我有如下的打字稿代码:-
export function getRootWindow():Window {
return window.top;
}
export function getRootDocument():HTMLDocument {
return getRootWindow().document;
}
declare global {
interface Document {
documentMode?: any;
}
}
export function isBrowserIE() {
return getRootDocument().documentMode;
}
export function addCssRule(cssString:string, num:number) {
let isIE = isBrowserIE();
if(getRootDocument().styleSheets[0] == undefined) {
let head = getRootDocument().head || getRootDocument().getElementsByTagName('head')[0];
let style = getRootDocument().createElement('style');
head.appendChild(style);
}
if(isIE) {
getRootDocument().styleSheets[0].addRule(cssString,num);
}else {
getRootDocument().styleSheets[0].insertRule(cssString,num);
}
}Run Code Online (Sandbox Code Playgroud)
这段代码在javascript中效果很好:-
<!DOCTYPE html>
<html>
<head>
</head>
<body style="color: #fff; font-family: arial, sans-sarif; background-color: #333; text-align: …Run Code Online (Sandbox Code Playgroud)我试图在 readme.md 文件中有一个下拉菜单,并在该可扩展区域中显示代码。
对于 md 文件,我看到有人使用对我有用的 ``` 。
下面的链接对于使用 md 文件和许多其他内容显示表格数据很有用:-
https://github.com/adam-p/markdown-here/wiki/Markdown-Cheatsheet
https://github.com/tchapi/markdown-cheatsheet/blob/master/README.md
为了显示下拉菜单,我发现使用带有摘要的详细信息标签有效:-
我正在尝试更新 md 文件并显示一些代码
<details>
<summary><h1 style="display:inline-block"> Advanced Topics </h1></summary>
```
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
template: `<nav>
<a routerLink="/signin" routerLinkActive="active">SignIn</a>
<a routerLink="/signup" routerLinkActive="active">SignUp</a>
</nav>
<router-outlet></router-outlet>`,
styleUrls: ['./app.component.css']
})
export class AppComponent {
}
```
</details>Run Code Online (Sandbox Code Playgroud)
但到目前为止我还没有成功。
如何显示格式化/突出显示的代码,就像我在详细信息标签内使用 ``` 时一样?
任何帮助,将不胜感激。
angular ×2
typescript ×2
css ×1
github ×1
html ×1
javascript ×1
markdown ×1
readme ×1
rxjs ×1
unit-testing ×1