小编jla*_*ang的帖子

使用mocha和typescript测试Paho MQTT Client时,"窗口未定义"

我用谷歌搜索了几天,但找不到任何关于如何测试Paho MQTT客户端的信息.我以某种天真的方式尝试过它,就像那样:

import { suite, test, slow, timeout, skip, only } from 'mocha-typescript';
import chai = require('chai');

var jsdom = require('jsdom');
var Paho: any;
const expect: any = chai.expect;
const host: string = '127.0.0.1';
const port: number = 1384;
const clientId1: string = 'testid1';
const clientId2: string = 'testid2';

let client1;
let client2;

describe('test', function () {
  it('should', function (done) {
    // emulate browser window, which is required by Paho
    jsdom.env("<html><body></body></html>", [],
      function (err: any, window: …
Run Code Online (Sandbox Code Playgroud)

javascript testing mqtt typescript paho

5
推荐指数
1
解决办法
459
查看次数

NestJs - Send Response from Exception Filter

我试图实现一个简单的行为:每当抛出异常时,我想将错误作为响应发送。我这种幼稚的代码看起来像这样,但根本没有响应:

异常过滤器:

import { ExceptionFilter, ArgumentsHost, Catch } from '@nestjs/common';

@Catch()
export class AnyExceptionFilter implements ExceptionFilter {
  catch(exception: any, host: ArgumentsHost) {
    return JSON.stringify(
      {
        error: exception,
      },
      null,
      4,
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

模块

@Module({
  imports: [],
  controllers: [AppController, TestController],
  providers: [AppService, AnyExceptionFilter],
})
export class AppModule {}
Run Code Online (Sandbox Code Playgroud)

主文件

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.useGlobalFilters(new AnyExceptionFilter());
  await app.listen(1212);
}
bootstrap();
Run Code Online (Sandbox Code Playgroud)

有什么我想念的吗?提前致谢 :)

exception-handling nestjs

5
推荐指数
1
解决办法
4975
查看次数

打字稿:省略'export'关键字似乎使界面全局化?

最近我在一个打字稿项目的VSCode中遇到了以下情况:

文件: some-interface.ts

// no import statements have been skipped. This is the whole file:
export interface SomeInterface {
    property: AnotherInterface;         
}
Run Code Online (Sandbox Code Playgroud)

和文件another-interface.ts::

export interface AnotherInterface {
    // ...
}
Run Code Online (Sandbox Code Playgroud)

好的 - 由于some-interface.tsVS代码中没有import语句,因此向我显示了AnotherInterface无法找到该类型的错误.当然这是预期的行为.但是,一旦我意外地删除了export关键字another-interface.ts- VS代码停止抱怨并且可以正确解决该类型.

那么有谁知道这里发生了什么?这是预期的行为,还是打字稿或vs代码的错误?

我用Google搜索,但在那里找不到提示.提前致谢!:)

typescript visual-studio-code

4
推荐指数
1
解决办法
29
查看次数

如何在角度js中的选项卡中添加图标

嗨我是角度js的新手,

我的问题是如何在角度js的标签中添加一个图标?这就是我到目前为止所拥有的:

<tabset panel-tabs="true" panel-class="{{demoTabbedPanelClass}}" heading="{{demoTabbedPanelHeading}}">
  <tab heading="Tab 1 some text ">sapiente doloribus deserunt et nam obcaecati recusandae possimus aperiam similique.</p>
  </tab>
  <tab heading="Tab 2 ded">
    <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Tenetur ipsam consectetur sint. Nobis facere illo iste quaerat sapiente doloribus deserunt et nam obcaecati recusandae possimus aperiam similique.</p>
  </tab>
</tabset>
Run Code Online (Sandbox Code Playgroud)

我正在补充 <tab heading="Tab 2 ded <span class="icon-print">print</span>">

但是它显示的内容与标题内部完全相同,而不是像我想象的那样渲染跨度.

请帮我.

javascript angularjs angular-ui-bootstrap

3
推荐指数
1
解决办法
7252
查看次数

VS Code 扩展:在工作区中查找和替换字符串

我用谷歌搜索了很多,并没有找到任何有效的方法来搜索内部特定文件vscode.workspace并替换找到的术语。

所以基本上我想搜索vscode.workspace一个名为 app.component.ts 的文件,并检查该文件是否包含 // my-marker。如果是这样,这个标记应该被其他一些字符串替换。

有谁知道这是否可能?如果是这样,如何?这是我的方法:

function createAppEnvironment(name: string)
{
  if(name != undefined)
  {
    // replace all blanks ' ' with dashes '-'
    name = name.replace(/\w/g, '-');

    vscode.workspace.findFiles('app/app.component.ts', '', 1).then(
        // all good
        (result: vscode.Uri[]) => {
            vscode.workspace.openTextDocument(result[0]);
            vscode.commands.executeCommand('edit.findAndReplace');
        },
        // rejected
        (reason: any) => {
            // output error
            vscode.window.showErrorMessage(reason);
        });

    // Display a message box to the user
    // vscode.window.showInformationMessage('Successfully created a new App!');
}
else
{
    vscode.window.showWarningMessage("Nothing was created, due to the …
Run Code Online (Sandbox Code Playgroud)

visual-studio-code vscode-extensions

3
推荐指数
1
解决办法
2967
查看次数

Angular 2 - 使用@ContentChildren过滤组件的内容

我正在尝试实现一个能够触发search(term: string)特定孩子的功能的搜索组件.如果对子项的搜索失败或者对子项的引用成功,则此搜索函数将返回null.

这是因为我想"收集"对列表中成功的角度组件的所有引用,以便我可以将它们设置为"new"ContentChildren,因此实际上进行基本过滤.

这是我到目前为止:

search.component.html

<input (value)="searchterm" />
<ng-content>
    <!-- all components that implements iSearchable here -->
</ng-content>
Run Code Online (Sandbox Code Playgroud)

search.component.ts

...
export class searchComponent implements OnChanges
{
    @Output('searchterm')
    public searchterm: string;

    // 1. Problem: ContentChildren does not work with interfaces?
    @ContentChildren(Isearchable)
    searchContent: QueryList<Isearchable>

    // 2. Problem: ngOnChanges will not fire when searchterm is changed
    ngOnChanges(event)
    {
        var toBeShown = [];

        // go through and let the components filter themselves
        for(let i = 0; i < this.searchContent.length; i++)
        {
            var …
Run Code Online (Sandbox Code Playgroud)

angular

2
推荐指数
1
解决办法
1918
查看次数