小编dam*_*amd的帖子

如何存根茉莉花模拟对象的方法?

根据Jasmine文档,可以像这样创建一个模拟:

jasmine.createSpyObj(someObject, ['method1', 'method2', ... ]);
Run Code Online (Sandbox Code Playgroud)

你如何存根这些方法之一?例如,如果要测试方法抛出异常时会发生什么,那么您将如何做?

javascript jasmine

66
推荐指数
3
解决办法
6万
查看次数

Babel支持Object.entries

我正在查看Object.values/Object.entries第3阶段提议,我真的想在我当前的JavaScript项目中使用它.

但是,我无法弄清楚是否有任何支持它的Babel预设.由于上面链接的GitHub存储库说它是第3阶段提案,我认为它将是babel-preset-stage-3的一部分,但似乎没有.

是否有任何Babel预设(甚至插件?)让我今天使用Object.entries?

javascript babeljs ecmascript-next

22
推荐指数
3
解决办法
2万
查看次数

转到实现而不是TypeScript声明

当我按住CmdVSCode的同时单击导入的变量时,通常最终会看到该变量的TypeScript声明。有什么方法可以让VSCode带我去了解它的定义吗?我自己没有使用TypeScript,因此该功能目前对我没有帮助。

visual-studio-code

17
推荐指数
3
解决办法
1534
查看次数

Django记录自定义管理命令

我有一个main在我的Django项目中命名的应用程序.这个应用程序有几个我想记录的管理命令,但是在stdout中没有显示任何内容,具有以下配置:

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'log_to_stdout': {
            'level': 'DEBUG',
            'class': 'logging.StreamHandler',
            'stream': sys.stdout,
            },
        },
    'loggers': {
        'main': {
            'handlers': ['log_to_stdout'],
            'level': 'DEBUG',
            'propagate': True,
            }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?我也尝试过使用my_project.main,但这也没用.我正在使用1.3.0决赛.

python django logging

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

在JavaScript中映射生成器上的函数

我有一个generateNumbers用JavaScript 调用的生成器和另一个生成器generateLargerNumbers,它生成每个生成的值并向其generateNumbers应用一个函数addOne,如下所示:

function addOne(value) {
  return value + 1
}

function* generateNumbers() {
  yield 1
  yield 2
  yield 3
}

function* generateLargerNumbers() {
  for (const number of generateNumbers()) {
    yield addOne(number)
  }
}
Run Code Online (Sandbox Code Playgroud)

如果没有从生成的值中构建数组,是否有任何更简单的方法可以做到这一点?我想的是:

function* generateLargerNumbers() {
  yield* generateNumbers().map(addOne) // obviously doesn't work
}
Run Code Online (Sandbox Code Playgroud)

javascript functional-programming generator

11
推荐指数
2
解决办法
3204
查看次数

Kendo UI:一个数据源,两个小部件

更新: 这是一个重现问题的链接

相关: 这是我的另一个问题,剑道UI地图发生了类似的问题,也许它可以帮助有人解决这个问题!它有一个失败和一个工作版本.


我在Angular单页面应用程序中使用Kendo UI的DataSource,DropDownList和Map.

我想为DropDownList和Map使用相同的DataSource对象.但是,Map的行为方式非常不可预测.

  1. 当我将DropDownList放在模板中的Map 之前时,只会填充DropDownList.检查网络流量显示确实只有一个请求正在进行.当我首先放置Map时,它们都会被填充并且会发出两个请求.
  2. 当我不使用任何承诺transport.read,但只是options.success立即使用静态值调用时,一切都按预期工作.正在进行两次通话.

在整个工作日里,我一直在梳头,所以任何帮助都非常感谢.

数据源服务:

m.factory('ourDataSource', function(foo, bar, baz) {
    return new kendo.data.DataSource({
        transport: {
            read: function(options) {
                foo().then(function (result) {
                    return bar(result);
                }).then(function (result) {
                    return baz(result);
                }).then(function (result) {
                    options.success(result);
                }).catch(function (err) {
                    options.error(err);
                });
            }
        }
    });
});
Run Code Online (Sandbox Code Playgroud)

控制器:

m.controller('ourController', ['ourDataSource', function(ourDataSource) {

    // set the data source of the dropdownlist
    this.ourDataSource = ourDataSource;

    // set up the map layers
    this.mapLayers = [{
        type: …
Run Code Online (Sandbox Code Playgroud)

javascript kendo-ui angularjs kendo-datasource kendo-map

9
推荐指数
1
解决办法
675
查看次数

Emacs:定义一个函数,用于加载定义函数本身的文件

我在我的Emacs设置中进行了一些重构,并且得出结论我想使用与默认文件不同的初始文件.所以基本上,在我的〜/ .emacs文件中,我有这个:

(load "/some/directory/init.el")
Run Code Online (Sandbox Code Playgroud)

到目前为止,这一切都很好.但是,现在我想重新定义一个我用了很久的旧命令,它会打开我的init文件:

(defun conf ()
  "Open a buffer with the user init file."
  (interactive)
  (find-file user-init-file))
Run Code Online (Sandbox Code Playgroud)

如你所见,无论我做什么,这都会打开〜/ .emacs.我希望它打开/some/directory/init.el,或者在conf命令本身定义的任何地方.

我该怎么办?

emacs

8
推荐指数
1
解决办法
194
查看次数

Webpack和以编程方式注入的内容脚本

我正在使用React和Webpack开发Chrome扩展程序.

在这个项目中,不同的模块将以编程方式使用注入内容脚本chrome.tabs.executeScript(null, {file: 'content-script-file.js'}).

这成了问题,因为我使用Webpack捆绑所有东西.基本上,后台脚本正在加载许多模块,这些模块都配置为在某些情况下以编程方式注入内容脚本.

但是,我无法弄清楚这些内容脚本将如何在捆绑的应用程序中"找到".它们从未显式导入,仅在executeScript调用中引用.

同时,内容脚本使用React,因此它们必须通过babel-loaderWebpack.

有任何想法吗?

javascript google-chrome-extension reactjs webpack

8
推荐指数
1
解决办法
1119
查看次数

Gulp:使用纯CSS编译Stylus和concat

我有一堆Stylus文件'./styles/stylus/**.styl'和一堆CSS文件'./styles/css/**.css'.

如何使用Gulp编译Stylus文件,将结果与所有CSS文件连接并输出到'./styles/out.css'

css stylus gulp

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

Spring LDAP基本用法

我试图通过设置最基本的工作程序来弄清楚Spring LDAP(不是 Spring安全事件)是如何工作的,但似乎实际的身份验证中断了.

这是我得到的错误:

Exception in thread "main" java.lang.NullPointerException
    at org.springframework.ldap.core.support.AbstractContextSource.getReadOnlyContext(AbstractContextSource.java:125)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:287)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:237)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:588)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:546)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:401)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:421)
    at org.springframework.ldap.core.LdapTemplate.search(LdapTemplate.java:441)

在抛出异常的方法中执行的代码是:

return getContext(authenticationSource.getPrincipal(),
                  authenticationSource.getCredentials());
Run Code Online (Sandbox Code Playgroud)

所以我似乎需要在应用程序上下文中设置身份验证源?我真的迷路了.

这是我的代码:

package se.test.connector.ldap;

import java.util.List;
import javax.naming.NamingException;
import javax.naming.directory.Attributes;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.ldap.core.AttributesMapper;
import org.springframework.ldap.core.DistinguishedName;
import org.springframework.ldap.core.LdapTemplate;
import org.springframework.ldap.core.support.LdapContextSource;
import org.springframework.ldap.filter.EqualsFilter;

public class LdapTest {

    public static void main(String[] args) {
        LdapContextSource ctxSrc = new LdapContextSource();
        ctxSrc.setUrl("ldap://<ldapUrl>:389");
        ctxSrc.setBase("DC=bar,DC=test,DC=foo");
        ctxSrc.setUserDn("<username>@bar.test.foo");
        ctxSrc.setPassword("<password>");

        LdapTemplate tmpl = …
Run Code Online (Sandbox Code Playgroud)

java spring spring-ldap

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