小编Ale*_*din的帖子

在 POST 请求中使用查询字符串是一种不好的做法吗?

有一个系统将POST请求从前端发送到后端。这些POST请求不使用主体将数据传递给服务器;相反,它在 URL 参数中使用查询字符串。

这些请求不发送文件或 JSON,仅发送几个字符串参数。

W3C 没有描述这种情况https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

使用查询字符串进行 POST 请求是否是一种不好的做法?由于安全、性能或体系结构原因,使用查询字符串是否会产生任何负面后果?

是否有任何约定定义不同类型请求的正文或查询字符串的用法?

javascript forms rest networking post

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

具有酶和TypeScript的浅层HOC

我有一个要测试的HOC,在浅层安装期间,我应该调用一些类方法:

it('Should not call dispatch', () => {
        const dispatch = jest.fn()
        const WrappedComponent = someHoc(DummyComponent)
        const instance = shallow(
          <WrappedComponent
            dispatch={dispatch}
          />,
        ).instance() as WrappedComponent
        instance.someMethod()
        expect(dispatch).toHaveBeenCalledTimes(0)
})
Run Code Online (Sandbox Code Playgroud)

测试工作正常,但TS编译器抛出错误

 Cannot find name 'WrappedComponent'.
Run Code Online (Sandbox Code Playgroud)

没错,因为WrappedComponent不是类型或类,但是如果我删除了

 as WrappedComponent
Run Code Online (Sandbox Code Playgroud)

行,TS抛出错误

Property 'someMethod' does not exist on type 'Component<{}, {}, any>'.
Run Code Online (Sandbox Code Playgroud)

另外,如果我将该行更改为

as typeof WrappedComponent
Run Code Online (Sandbox Code Playgroud)

someHoc说明:

import ...

interface State {
  /*state*/
}

interface Props {
  dispatch: Dispatch<Action>
  /*props*/
}

export someHoc = <T extends {}>(
  ChildComponent: React.ComponentClass<T>,
) => {
  class Wrapper …
Run Code Online (Sandbox Code Playgroud)

javascript typescript reactjs enzyme

6
推荐指数
1
解决办法
1467
查看次数

标签 统计

javascript ×2

enzyme ×1

forms ×1

networking ×1

post ×1

reactjs ×1

rest ×1

typescript ×1