在 NextJs 13+ 中,使用实验性 App 文件夹,可以编写异步服务器组件,如文档所述:
export default async function Page({ params: { username } }) {
// Initiate both requests in parallel
const artistData = getArtist(username);
const albumsData = getArtistAlbums(username);
// Wait for the promises to resolve
const [artist, albums] = await Promise.all([artistData, albumsData]);
return (
<>
<h1>{artist.name}</h1>
<Albums list={albums}></Albums>
</>
);
}
Run Code Online (Sandbox Code Playgroud)
这是一项非常有用的技术,我已经在应用程序的许多页面中实现了。但是,当使用 jest 进行测试时,我发现我无法编写任何能够呈现此默认导出的测试:
it('should render without crashing', async () => {
...(setup mocks)
const { container } = await waitFor(() => render(<Page …Run Code Online (Sandbox Code Playgroud) typescript jestjs next.js react-testing-library react-server-components
例如,array.pop不需要爆炸来永久改变阵列.为什么会这样,如果没有这种一致性,开发这些某些Ruby方法背后的原因是什么呢?
我正在开发一个 CMS 项目,刚刚遇到一个问题。_userEvent.default.clear is not a function。
import user from \'@testing-library/user-event\'\n\ntest(\'can edit label\', async () => {\n createArticleMock()\n await renderRootAndInitStore(rightNowTeasers, globalInitialState)\n\n const index = 1\n const input = screen.getByDisplayValue(labels[index])\n const newLabel = \'V\xc3\x84RLDEN\'\n user.clear(input)\n user.type(input, newLabel)\n\n expect(await screen.findByDisplayValue(newLabel))\n user.click(screen.getByTestId(\'settings-form-save\'))\n await screen.findByText(newLabel)\n})\nRun Code Online (Sandbox Code Playgroud)\n\n当我访问时@testing-library/user-event,我看到那些线条
// Definitions by: Wu Haotian <https://github.com/whtsky>\nexport interface IUserOptions {\n allAtOnce?: boolean;\n delay?: number;\n}\n\nexport interface ITabUserOptions {\n shift?: boolean;\n focusTrap?: Document | Element;\n}\n\nexport type TargetElement = Element | Window;\n\ndeclare const userEvent: {\n …Run Code Online (Sandbox Code Playgroud) 我在 javascript 中有以下两个对象数组
data1 = [
{
id: 123,
option: "ABC",
value: "123"
},
{
id: 234,
option: "DFG",
value: "234"
}
];
data2 = [
{
id: 123,
option: "ABC",
value: "123"
}
];
Run Code Online (Sandbox Code Playgroud)
当 id 与第二个对象数组匹配时,我想仅在该特定 id 的第一个对象数组中将值(属性)设置为 0。就像下面一样,一旦 id 123 在两个数组中都匹配,那么 data1 数组应该如下所示
data1 = [
{
id: 123,
option: "ABC",
value: "0"
},
{
id: 234,
option: "DFG",
value: "234"
}
];
Run Code Online (Sandbox Code Playgroud)
如何实现上述场景?
javascript ×2
arrays ×1
jestjs ×1
methods ×1
next.js ×1
reactjs ×1
ruby ×1
typescript ×1
user-event ×1