我只是在尝试这个库,似乎无法通过他们的 ARIA 角色访问元素。
我使用 angular 10.0.6、jest 26.2.1 以及 jest-preset-angular 8.2.1 和 @testing-library/angular 10.0.1。我相信已经按照https://www.npmjs.com/package/jest-preset-angular和https://testing-library.com/docs/angular-testing-library/intro 中的描述设置了项目
这是我要测试的组件:
<h1>{{title}}</h1>
<img src="../assets/chuck-norris-logo.jpg" alt="Chuck Norris Approves!">
<p role="status">{{jokeText}}</p>
<button (click)="refreshJoke()">Refresh</button>
Run Code Online (Sandbox Code Playgroud)
以及一些测试的相关部分:
test('refreshes joke on click', async () => {
const component = await render(AppComponent);
const button = component.getByRole('button');
fireEvent.click(button);
});
Run Code Online (Sandbox Code Playgroud)
但是,我收到一条错误消息,指出找不到该角色。
TestingLibraryElementError: Unable to find an accessible element with the role "button"
There are no accessible roles. But there might be some inaccessible roles. If you wish to access them, then …Run Code Online (Sandbox Code Playgroud) 我想知道是否有可能在具有 monadic 属性的列表或类列表结构上实现类似于 Kotlin 中 Haskell 的 do-notation 的东西。
以下面的例子为例:
fun <A, B> cartesianProduct(xs: List<A>, ys: List<B>): List<Pair<A, B>> =
xs.flatMap { x -> ys.flatMap { y -> listOf(x to y) } }
Run Code Online (Sandbox Code Playgroud)
如果我能写一些类似的东西就好了
suspend fun <A, B> cartesianProduct(xs: List<A>, ys: List<B>): List<Pair<A, B>> =
list {
val x = xs.bind()
val y = xs.bind()
yield(x to y)
}
Run Code Online (Sandbox Code Playgroud)
Arrow-Kt 使用协程为nullable、option 和 eval定义了类似的理解。我查看了实现及其效果文档,但我无法将概念转换为列表。这在 kotlin 中甚至可能吗?