在我的应用程序中,当我访问页面时,它会发出一些网络请求以获取数据并将其显示在页面上。之后,您单击按钮并填写字段以过滤该数据。
我有一个赛普拉斯测试,基本上可以访问该页面,应用一些过滤器,并确保dom中的内容看起来正确:
it(`filters the data by 'price'`, () => {
cy.server()
cy.route('POST', 'http://my-api.biz/api').as('apiRequest')
cy.visit('/')
// initial page load loads the min and max price bounds for the UI,
// as well as the data to initially populate the page. they happen
// to hit the same URL with different POST params
cy.wait(['@apiRequest', '@apiRequest'])
cy.get('#price-filter-min').type('1000')
cy.get('#price-filter-max').type('1400')
// wait for data to get refreshed
cy.wait('@apiRequest')
cy
.get('[data-test-column="price"]')
.each($el => {
const value = parseFloat($el.text())
expect(value).to.be.gte(1000)
expect(value).to.be.lte(1400)
})
})
Run Code Online (Sandbox Code Playgroud)
但是有时柏似乎加载了页面,在等待之前 …
我想离开一个分支(例如git switch HEAD -d
),进行提交,然后将其推送到远程(例如github),而不在那里创建分支。
用例是有时我想问某人“这就是你的意思吗?” 并链接到提交,但我不希望 github 提示我创建 PR,或者让这个垃圾出现在您可以列出分支的任何地方。
如何在不创建分支的情况下推送 git 提交?
使用 typescript 的 jsdoc 支持键入以下javascript代码:
const [optionalNumber, setOptionalNumber] = useState(null)
const handleClick = () => {
setOptionalNumber(42)
// ^-- Argument of type '42' is not assignable to parameter of type 'SetStateAction<null>'
}
Run Code Online (Sandbox Code Playgroud)
我目前解决这个问题的方式有效,但有点难看:
const [optional, setOptional] = useState(
/** @type {number|null} */ (null)
)
Run Code Online (Sandbox Code Playgroud)
我怎样才能在不使用铸造的情况下实现这一点?我想要optional
一种null | number
, 并且setOptional
只接受null | number
作为参数。
代码和盒子展示了这一点:https ://codesandbox.io/s/optimistic-villani-kbudi?fontsize
=14