我正在将 .NET Core 2.1 升级到 .NET Core 3.0,我在这里看到我必须使用UseEndpoints. 然而,在一些网页我已经看到或者它MapControllerRoute,MapDefaultControllerRoute或MapControllers。
我查看了文档,发现它MapDefaultControllerRoute与MapControllerRoute("default", "{controller=Home}/{action=Index}/{id?}"). 但我不明白与MapControllers. 最后一个函数实际上是做什么的?文档说:“将控制器操作的端点添加到 IEndpointRouteBuilder 而不指定任何路由。”,但我不明白,抱歉。
我正在使用ts-jest(Jest和TypeScript),并希望为所有测试套件配置一些全局设置(初始化测试数据库).
我发现globalSetupjest配置中有选项:
"jest": {
"globalSetup": "./jest-config.js"
}
Run Code Online (Sandbox Code Playgroud)
但只有.js文件可用于设置.我想使用.ts文件,因为我的所有代码都包括在TypeScript中进行设置的代码.
我怎样才能做到这一点?
我正在使用 Typescript 测试 React Native 应用程序构建。
玩笑输出:
不变违规:元素类型无效:预期为字符串(对于内置组件)或类/函数(对于复合组件)但得到:对象
附言。无论如何 Rn 工作也渲染方法,但我不明白代码中的这个错误在哪里。任何人都可以帮助我吗?
App.test.tsx
import 'react-native';
import * as React from 'react';
import App from '../App';
import renderer from 'react-test-renderer';
it('renders correctly', () => {
renderer.create(<App />);
});
Run Code Online (Sandbox Code Playgroud)

在webpack 中使用 jest的教程提到了这个语法:$1,我一直无法弄清楚它是做什么的。我正在处理两个具有相同别名的项目,但一个使用 jest 配置:
"moduleNameMapper": {
"^myModule(.*)$": "<rootDir>/src/components/react",
}
Run Code Online (Sandbox Code Playgroud)
当一个人与
"moduleNameMapper": {
"^myModule(.*)$": "<rootDir>/src/components/react$1",
}
Run Code Online (Sandbox Code Playgroud)
$1 语法有什么作用?
我正在使用Angular 7和Jest。当我与一起开玩笑时--codecoverage,我所有的测试都通过了,但是构造器中的许多分支没有被覆盖(类似于:构造器上的分支未覆盖)。
我花了很多时间检查所有地方如何解决它,似乎不得不升级jest-preset-angular到版本7。完成之后,我的所有测试套件都无法运行,并显示以下消息:
src/app/whatever.component.spec.ts
? Test suite failed to run
TypeScript diagnostics (customize using `[jest-config].globals.ts-jest.diagnostics` option):
error TS2688: Cannot find type definition file for 'jasmine'.
Run Code Online (Sandbox Code Playgroud)
我一直在寻找周围,我想申请我找到了解决方案(如无法找到“茉莉花”类型的定义文件,错误TS2688错误:无法找到“开玩笑”类型的定义文件,...),但没有工作。
我在这里复制package.json中的一些依赖项:
"jest": "^24.1.0",
"jest-junit": "^6.3.0",
"jest-preset-angular": "^7.0.1",
"ts-node": "~7.0.1",
"tslint": "~5.9.1",
"typescript": "3.2.4"
Run Code Online (Sandbox Code Playgroud)
我以前的版本是:
"jest-preset-angular": "^6.0.2",
Run Code Online (Sandbox Code Playgroud)
我不知道我可以提供哪些其他信息。如果有遗漏,如果您能在拒绝投票之前(实际上是代替)告诉我,我将不胜感激。
更新:我从Angular 6和Jasmine开始了我的项目,并将其更新为Angular 7和Jest。我不知道这是否是重要信息。
谢谢!
我正在使用Jest和Enzyme进行测试.我测试正常事件没有问题,但我正在努力找到如何触发和测试来自Native Modules的组件中的事件的正确方法.在我的Jest设置中,我有以下内容:
jest.mock('NativeEventEmitter', () => class MockNativeEventEmitter{
addListener = () => jest.fn()
removeListener = () => jest.fn()
removeAllListeners = () => jest.fn()
});
Run Code Online (Sandbox Code Playgroud)
但是,我不确定在测试中我如何实际调度事件.因此,例如,当用户摇动设备时,我有一个Native模块.在组件本身内,这样设置如下:
shakeEvents: ['shaken],
deviceShakeEmitter: {},
componentDidMount() {
this.deviceShakeEmitter = new NativeEventEmitter(Shake)
this.deviceShakeEmitter.addListener('shaken', this['shaken'])
},
Run Code Online (Sandbox Code Playgroud)
我知道对于内置事件我可以使用jest.simulate('press')等,但对于自定义事件,我很难理解我如何在测试中处理这个问题.
我正在一个结构上运行一个示例 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) 我正在处理两个几乎相同的测试用例,我应该断言期望两个 NgRx 效果返回一个布尔值流。在第一个测试用例中一切都按预期工作,尽管对第二个测试用例执行相同的操作,但我无法使其按预期工作。无论我做什么,收到的值总是一个空数组:
expect(received).toEqual(expected) // deep equality
- Expected
+ Received
- Array [
- Object {
- "frame": 10,
- "notification": Notification {
- "error": undefined,
- "hasValue": true,
- "kind": "N",
- "value": true,
- },
- },
- ]
+ Array []
Run Code Online (Sandbox Code Playgroud)
logger.effects.spec.ts:
expect(received).toEqual(expected) // deep equality
- Expected
+ Received
- Array [
- Object {
- "frame": 10,
- "notification": Notification {
- "error": undefined,
- "hasValue": true,
- "kind": "N",
- "value": true, …Run Code Online (Sandbox Code Playgroud) 使用 C# 9,您可以执行以下操作:
public record Person(string FirstName, string LastName);
Run Code Online (Sandbox Code Playgroud)
来定义记录Person。这相当于:
public record Person
{
public string FirstName { get; init; }
public string LastName { get; init; }
public Person(string firstName, string lastName)
=> (FirstName, LastName) = (firstName, lastName);
public void Deconstruct(out string firstName, out string lastName)
=> (firstName, lastName) = (FirstName, LastName);
}
Run Code Online (Sandbox Code Playgroud)
根据这个页面。
因此,元素FirstName和LastName作为构造函数的属性和参数。作为属性,这些元素应该大写,但如果我这样做,SA1313 会抱怨:Parameter '__' must begin with lower-case letter..
这是 StyleCop 的问题还是我做错了什么?
jestjs ×8
angular ×2
react-native ×2
typescript ×2
asp.net-core ×1
c#-9.0 ×1
ngrx ×1
ngrx-effects ×1
stylecop ×1
webpack ×1