我有一个自定义的 eslint-config,它有几个用于各种包的插件,包括 jest。我将主要设置为一个索引,它只是扩展其他文件。
长话短说我有一个笑话配置文件。那看起来像。
module.exports = {
plugins: ['jest'],
rules: {
'jest/no-disabled-tests': 'warn',
'jest/no-focused-tests': 'error',
'jest/no-identical-title': 'error',
'jest/valid-expect': 'error',
'jest/no-alias-methods': 'off',
'jest/no-jest-import': 'error',
'jest/no-large-snapshots': ['warn', {maxSize: 300}],
'jest/no-test-prefixes': 'error',
'jest/prefer-to-contain': 'warn',
'jest/prefer-to-have-length': 'warn',
'jest/valid-describe': 'error',
'jest/valid-expect-in-promise': 'error',
'jest/consistent-test-it': 'off',
'jest/lowercase-name': 'off',
'jest/no-hooks': 'off',
'jest/no-jasmine-globals': 'off',
'jest/no-test-callback': 'off',
'jest/prefer-expect-assertions': 'off',
'jest/prefer-to-be-null': 'off',
'jest/prefer-to-be-undefined': 'off',
'jest/require-tothrow-message': 'off',
'jest/expect-expect': 'off',
'jest/no-test-return-statement': 'off',
'jest/prefer-inline-snapshots': 'off',
'jest/prefer-strict-equal': 'off',
'jest/prefer-spy-on': 'off',
'jest/prefer-todo': 'warn',
'jest/prefer-called-with': 'error',
'jest/no-truthy-falsy': 'off',
'jest/no-empty-title': 'error',
'jest/no-mocks-import': 'error',
'jest/no-commented-out-tests': 'warn',
},
env: { …Run Code Online (Sandbox Code Playgroud) 我们开始混合一些es6模块和eslint只是抱怨当你不使用sourceType:import时导入/导出
Parsing error: 'import' and 'export' may appear only with 'sourceType: module'at line 1 col 1
Run Code Online (Sandbox Code Playgroud)
但是,如果我将sourceType更改为module,那么每个文件都有'use strict'; 在顶部得到标记说模块中不需要使用严格.
模块是我的jsx文件,我的js文件是POJ所以我需要两个sourceTypes来运行.
关于如何强制eslint与模块和脚本一起行为的任何想法?我想避免运行两个单独的eslintrc文件和规则集只是为了让一个是模块而另一个是脚本.
我有一个 redux 文件,其中包含我的减速器和我通过命名导出的所有操作。
export const reducer = (state, action) => ...
export myAction = action => {
return {type: 'ACTION', action}
}
...
Run Code Online (Sandbox Code Playgroud)
在我的测试文件中,我导入了减速器和操作。我有一个 renderWithRedux,它接收 reducer 并在里面创建一个真正的store。
function renderWithRedux(ui, reducer = combineReducers(reducers), initialState = {}) {
const store = createStore(reducer, initialState)
const utils = render(<Provider store={store}>{ui}</Provider>)
return {
...utils,
store,
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我正在渲染的组件是在连接组件的 mapDispatchToProps 中传递的动作。
export default connect(mapStateToProps, { myAction })(MyComponent)
Run Code Online (Sandbox Code Playgroud)
我想在我的特定用例中模拟myAction这个动作实际上是一个 thunk,我想看看商店是否更新。
我的问题是如何模拟 myAction 而不是减速器。我试过了
jest.mock('./reducerFile', () => {
return jest.fn().mockImplementation(() => {
return { …Run Code Online (Sandbox Code Playgroud) 好的,我正在为我们的密码策略编写密码检查器,这需要4个主要分类中的3个.我遇到问题的地方是特殊字符匹配.
这是我到目前为止所拥有的:
private function PasswordRequirements($ComplexityCount) {
$Count = 0;
if(preg_match("/\d/", $this->PostedData['password']) > 0) {
$Count++;
}
if(preg_match("/[A-Z]/", $this->PostedData['password']) > 0) {
$Count++;
}
if(preg_match("/[a-z]/", $this->PostedData['password']) > 0) {
$Count++;
}
// This is where I need help
if(preg_match("/[~`!@#$%^&*()_-+=\[\]{}\|\\:;\"\'<,>.]/", $this->PostedData['password']) > 0) {
$Count++;
}
if($Count >= $ComplexityCount) {
return true;
} else {
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
所以基本上我正在做的是检查每个案例的字符串,数字,大写,小写和特殊字符.我们对任何特殊字符没有任何限制,我还需要unicode字符.\ W在这种情况下工作还是会再包含数字?我找不到关于\ W的精彩文档,所以我不清楚这一部分.
有没有人知道一个简单的正则表达式,涵盖所有特殊字符和不包含数字和字母的unicode字符?
任何人都可以自由使用它,因为我认为不止一些人一直在寻找这个.