小编Tre*_*ams的帖子

带有命名插座的角度路由器链接(角度 5.0.2)

我已阅读有关此问题的所有帖子,但没有一个对我有用。

我有一个应用程序模块,一个路由模块,没有其他“模块”。我发现的是...

  1. 标准路由可以从任何组件链接到
  2. 带有命名出口的路由只能从默认的应用程序组件链接到,而不能从其他组件链接到
  3. 使用 routerLink 从应用程序组件以外的任何内容链接到命名插座会导致“错误:无法匹配任何路由。URL 段:”

我的路线是这样...

{path: 'hellocontent', component: ContentHelloWorldComponentComponent,
pathMatch: 'full', outlet: 'helloc'},
Run Code Online (Sandbox Code Playgroud)

路由器链接是...

<a [routerLink]="[{ outlets: { helloc: ['hellocontent'] } }]">action</a>.
Run Code Online (Sandbox Code Playgroud)

我的路由器插座是...

<router-outlet name="helloc"></router-outlet>
<router-outlet></router-outlet>
Run Code Online (Sandbox Code Playgroud)

该路由器链接在标准的 angular app.component.html 中完美运行,但不适用于任何其他组件。它总是导致“错误:无法匹配任何路由。URL 段:”。

一旦我删除了命名插座,并将 routerLink 更改为... <a routerLink="hellocontent">action</a>在应用程序组件或<a routerLink="/hellocontent">action</a>另一个组件中,它就可以完美运行,但只能在主插座中使用。

因为它可能很重要,我链接的组件当然也在它们自己的路由中定义,例如......

{path: 'hello-world', component: HelloWorldComponentComponent}
Run Code Online (Sandbox Code Playgroud)

这是预期的行为,即命名插座只能从它们定义的组件内访问吗?奇怪的是,我的大部分 html 包装器都在 app.component.html 中,但是除了主插座之外的任何东西都不能从另一个组件中工作。

angular

7
推荐指数
1
解决办法
1万
查看次数

对子文件夹中的所有 go 模块运行测试

我使用 git 的实用程序创建了以下目录树。

./git-logbranch/git-logbranch_test.go
./git-logbranch/git-logbranch.go
./git-logbranch/go.mod
./git-issue/git-issue_test.go
./git-issue/go.mod
./git-issue/git-issue.go
./main.go
./go.mod
Run Code Online (Sandbox Code Playgroud)

我读过几篇文章,说“./...”将自动在所有子文件夹中运行测试,但实际上并没有这样做。这就是我正在运行的内容和得到的输出:

$ go test ./...
?       main    [no test files]

Run Code Online (Sandbox Code Playgroud)

以下是子文件夹的一些输出示例。如您所见,各个测试有效:

$ go test ./...
ok      git_logbranch   0.001s

$ go test ./...
ok      git_issue   (cached)
Run Code Online (Sandbox Code Playgroud)

关于如何同时运行所有这些测试有什么想法吗?

go

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

选择带有测试库的下拉元素

显然我根本不理解测试库。它们具有“单击”功能,但似乎没有用于从选择元素中选择简单下拉选项的功能。这是失败的,表示选择了 0,而不是预期的 1。我如何使选择工作?


import React from "react";
import {render} from '@testing-library/react'
import {screen} from '@testing-library/dom'

let container: any;
beforeEach(() => {
    container = document.createElement('div');
    document.body.appendChild(container);
});

afterEach(() => {
    document.body.removeChild(container);
    container.remove();
    container = null;
});

it('AddRental should display', () => {
    render(<select name="town" data-testid="town" className="form-control"
                   aria-label="Select the Town">
        <option value="0">--Town--</option>
        <option value="1">My town</option>
        <option value="2">Your Town</option>
        <option value="3">The other town</option>
    </select>, {container});
    const dropdown = screen.getByTestId('town');
    expect(dropdown.value)
        .toBe('0');
    dropdown.click();
    const athabascaOption = screen.getByText('My town');
    athabascaOption.click();
    const byTestId = screen.getByTestId('town');
    expect(byTestId.value) …
Run Code Online (Sandbox Code Playgroud)

testing-library

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

标签 统计

angular ×1

go ×1

testing-library ×1