我有一个React+vite应用程序,我正在为其编写测试以涵盖应用程序启动时的前端路由重定向逻辑。
路由由 v6 处理react-router,所有与路由相关的组件都包装在React.lazy. 测试是由运行的vitest,我正在使用react-testing-library助手
所有测试都是相似的,看起来像这样
it('Redirects from app root to red room if the user has a red shirt', async () => {
getUser.mockReturnValue(redShirtUser);
render(MyTestedComponent, { wrapper });
await waitFor(() => expect(screen.getByText('Welcome to the red room'));
expect(history.location.pathname).toBe('/red-room');
});
Run Code Online (Sandbox Code Playgroud)
然而,其中一项测试花费的时间比其他测试要长得多,甚至waitFor超时。我可以指定更长的超时waitFor,但它仍然无法在 CI 上可靠地运行。如果测试是其文件中唯一的测试/唯一正在执行的测试,也会发生这种情况。
我已经将缓慢的部分(通过调试的魔力console.log)缩小为惰性import()语句 - 导入并执行模块需要花费很多时间(秒)。
我该如何调试这个?是否有已知的因素会导致(惰性)导入变慢?
首先,让我告诉你codez:
a = array([...])
for n in range(10000):
func_curry = functools.partial(func, y=n)
result = array(map(func_curry, a))
do_something_else(result)
...
Run Code Online (Sandbox Code Playgroud)
我在这里做的是尝试应用于func数组,每次更改func第二个参数的值.这是SLOOOOW(每次迭代创建一个新函数肯定没有帮助),我也觉得我错过了这样做的pythonic方式.有什么建议吗?
能给我2D阵列的解决方案是个好主意吗?我不知道,但也许是.
可能的问题的答案:
do_something_else()隐藏此)我有这个问题使用解决方案与组件和ui-router,解决后承诺的数据"未定义"在控制器中
服务:
class userService {
constructor ($http, ConfigService, authService) {
this.$http = $http;
this.API_URL = `${ConfigService.apiBase}`;
this.authService = authService;
}
testAuth () {
return this.$http.get(this.API_URL + '/test-auth')
}
getCollaboratores () {
return this.$http.get(this.API_URL + '/collaboratores').then(
(resolve) => { // promise resolve
console.log('Success',resolve.data);
}
)
}
getAccount () {
var config = {
headers: { "X-Shark-CollaboratoreId" : "1"}
};
return this.$http.get(this.API_URL + '/accounts' + '/' + 1, config).then(
(resolve) => { // promise resolve
console.log('Success',resolve.data);
}
)
}
Run Code Online (Sandbox Code Playgroud)
模块/组件/路由:
.config(($stateProvider, $urlRouterProvider) …Run Code Online (Sandbox Code Playgroud) 使用标准的Django模板系统,是否有任何片段/可重复使用的模板标签将一段文本中的前n个单词包含在标签中,以便我可以设置它们的样式?
我理想的是:
{{item.description|wrap:"3 span big"}}
Run Code Online (Sandbox Code Playgroud)
哪个输出:
<span class="big">Lorem ipsum dolor</span> sit amet, consectetur adipiscing elit.
Run Code Online (Sandbox Code Playgroud)
如果出于任何原因,这将是不可行或非常难以获得的,我可以使用JavaScript并在客户端执行,但我希望能够在页面输出上执行此操作.