小编Sen*_*nza的帖子

在Angular 2服务中测试异步(Promise)方法

这是一个有趣的问题:我正在尝试测试使用Ionic BarcodeScanner的服务.我有一个基于离子单元测试库的repo ,以便尝试测试.我正在嘲笑BarcodeScanner.scan方法spyOn(..).and.callFake(..)

问题:当我从组件调用扫描方法时,它可以工作.当我在服务中执行完全相同的操作时,它会抛出超时.

组件测试代码:

it("should be able to set a spy on the scanner and test the component", done => {
    const testBC = "123456";
    const spy = spyOn(TestBed.get(BarcodeScanner), "scan");
    spy.and.callFake(() => {
        return new Promise((resolve, reject) => {
            resolve(testBC);
        })
    });

        component.testScanner().then(res => {
            expect(res).toBe(testBC);
            done();
        }, reason => {
            expect(true).toBe(false);
            done();
        })
});
Run Code Online (Sandbox Code Playgroud)

服务测试代码:

it("should be able to set a spy on the scanner and test the service", done => {
    const testBC = …
Run Code Online (Sandbox Code Playgroud)

angular-services angular2-services ionic3 angular

16
推荐指数
1
解决办法
649
查看次数

应用如何获取我的电话号码以寻找朋友?

我目前正在开发一个cordova网络应用程序.

我想知道像Runkeeper这样的应用程序如何向我显示我的地址簿的联系人,这些联系人也在使用Runkeeper.每个联系人都有一个小电话符号,所以我猜这个链接是通过电话号码建立的.

Runkeeper从来没有得到我或我朋友的电话号码,但是SIM卡无法读取.

我能想到的唯一可能的方法是,Runkeeper从AccountManager读取我的其他帐户并使用我的WhatsApp-ID建立连接...

有人知道这是怎么回事吗?我可以在我的cordova应用程序中做到吗?

android cordova

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

将index.html中的引用自动复制到karma.conf.js

我正在尝试为我的测试生成一个karma.conf.js.

我的应用程序已经有大约30个标签引用我的代码.我正在以模块化结构编写我的AngularJS代码,就像这里推荐的那样.

我想知道如何不再将所有参考文献写入karma.conf.js ..有没有人知道这个的解决方案?

我查看了https://preview.npmjs.com/package/karma-loadscripts-preprocessor但它没有完成这项工作.似乎是从cdn-sources加载外部脚本.

在写我自己的shell脚本之前,我有点卡住了,这对我有用.

javascript node.js angularjs karma-runner

5
推荐指数
1
解决办法
631
查看次数

即使对于用户www-data可写,is_writable对于NFS共享也返回false

我有一个相对的文件夹'files / crm-upload',我想在其中上传文件。我的代码检查is_writable()是否为true,只有在这种情况下才继续进行。

该文件夹作为带有rw和sec = sys的NFS共享挂载。

我已经编写了一个测试脚本,我也在apache上执行了该脚本以查看访问权限,结果是:

files/crm-upload/php_touch modification time has been changed to present time 
My effective UID is 33 but my UID is really 33
files/crm-upload/ is owned by 33 and has permissions 40777
is_readable('files/crm-upload/') gives true
is_readable('files/crm-upload/php_touch') gives true
is_writable('files/crm-upload/') gives false
is_writable('files/crm-upload/php_touch') gives true
is_writable('files/crm-upload/25/') gives true
is_writable('files/images/') gives true
file_exists('files/crm-upload/') gives true
file_exists('files/crm-upload/php_touch') gives true
Some stat uids: 

files/crm-upload/: 33
files/crm-upload/php_touch: 33
files/images/: 33
Run Code Online (Sandbox Code Playgroud)

所以:

  • 触摸共享上的文件有效
  • uid是正确的
  • 目录具有正确的权限
  • 共享中的子文件夹和文件的is_writable返回true

怎么可能只有已挂载共享的根文件夹不可写,而其他所有东西都不能写?

这是Ubuntu 18.04。客户端,没有运行SELinux ...

php linux apache ubuntu nfs

5
推荐指数
1
解决办法
168
查看次数

Java:在方法中返回未知的泛型类型

方法

Filter<T,U> connect(final Filter<T,U> filter) {
...
return filter
}
Run Code Online (Sandbox Code Playgroud)

在课堂上

class Pipe<T>
Run Code Online (Sandbox Code Playgroud)

我收到错误"无法解析U".我们的想法是在不知道U类型的情况下,通常返回具有相同两种类型的相同过滤器.我怎么做?

目标是能够在不提供类型参数的情况下进行链接,因为它们不会被修改:

(new Pipe<Integer>).connect(new Filter<>(...)).connect(new Pipe<>)...
Run Code Online (Sandbox Code Playgroud)

上述expamle中Filter之后的第二个Pipe应隐式为泛型类型Integer.

java generics

0
推荐指数
1
解决办法
333
查看次数