小编Dan*_*ppo的帖子

jupyter 实验室中的自动单元格执行计时

在 jupyter notebook 中,我可以使用nbextensions配置自动单元计时,结果如下:

jupyter_notebook

我怎样才能在 jupyter实验室中做到这一点?我没有找到任何做类似事情的扩展。

Obs.:我知道用%%time魔法可以达到类似的结果,但我希望它是自动的,所以我不必在每个单元格的开头放置魔法函数。

ipython jupyter jupyter-notebook jupyter-lab

23
推荐指数
4
解决办法
8928
查看次数

使用继承和全局注入器进行 Angular 7 测试

我正在 Angular 7 中启动一个新项目,并有一个基础组件来集中我的一些全局变量和服务。由于项目可能变得相当大,我选择这种方法是为了避免在每个组件的开头以及 super() 调用时进行大量导入。

为此,我实现了此处描述的方法,其中外部类存储要在基本组件中使用的依赖项注入器。正如此处所讨论的,必须进行修改以符合 Angular 7(注入器必须在 AppModule 处初始化)。(见下面的笨蛋)

这对于运行项目来说效果很好,当我尝试运行单元测试(使用 karma-jasmine)时,问题就出现了。由于 AppInjector 是在模块中初始化的,因此测试运行不会对其进行初始化。然后,由于我的基本组件尝试调用注入器的函数,因此它崩溃了。

如果有人对此有任何解决方案,无论是通过修改测试结构还是 AppInjector 本身,我们将不胜感激。

这是一个包含所有涉及代码的插件。该示例是使用 primeng toast 模块的全局通知组件和基础组件中的全局通知服务。(我无法让 plunker 正常工作,某种 MIME 类型错误,但代码都在那里)

https://next.plnkr.co/edit/7v5nB8cORWsnpPAL?preview

当我运行 ng test 时,这是我得到的错误:

Chrome 71.0.3578 (Windows 10.0.0) AppComponent should create the app FAILED
        TypeError: Cannot read property 'get' of undefined
            at NotificationsComponent.BaseComponent (http://localhost:9876/src/app/components/base.component.ts?:22:50)
            at new NotificationsComponent (http://localhost:9876/src/app/components/utils/notifications/notifications.component.ts?:17:13)
            at createClass (http://localhost:9876/node_modules/@angular/core/fesm5/core.js?:20716:1)
            at createDirectiveInstance (http://localhost:9876/node_modules/@angular/core/fesm5/core.js?:20595:1)
            at createViewNodes (http://localhost:9876/node_modules/@angular/core/fesm5/core.js?:21821:1)
            at callViewAction (http://localhost:9876/node_modules/@angular/core/fesm5/core.js?:22137:1)
            at execComponentViewsAction (http://localhost:9876/node_modules/@angular/core/fesm5/core.js?:22056:1)
            at createViewNodes (http://localhost:9876/node_modules/@angular/core/fesm5/core.js?:21849:1)
            at createRootView (http://localhost:9876/node_modules/@angular/core/fesm5/core.js?:21735:1) …
Run Code Online (Sandbox Code Playgroud)

frontend dependency-injection karma-jasmine angular angular7

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