小编pot*_*mok的帖子

FB.init已被调用

我正在构建facebook iframe app.我的应用程序加载一次(我收到signed_request一次),然后使用内部域链接浏览iframe中的页面.我注意到我在Chrome和Firefox中看到了这些奇怪的消息

FB.init has already been called - this could indicate a problem
Run Code Online (Sandbox Code Playgroud)

我很确定这种方法只被调用一次,而且似乎Facebook要求我在每次应用程序加载时调用一次(不是每页一次).

window.fbAsyncInit = function() {
  FB.init({
    appId: param('facebook_app_id'),
    frictionlessRequests: true,
    oauth: true,
    channelUrl: site_url('/channel.html')
  })
}
Run Code Online (Sandbox Code Playgroud)

我在这里犯了什么错误(如果有的话)?

facebook opengraph

52
推荐指数
2
解决办法
4万
查看次数

如何模拟nodejs中的请求和响应来测试中间件/控制器?

我的应用程序有几个层次:中间件,控制器,管理器.控制器接口与中间件一样:( req,res,next).

所以我的问题是:如何在不启动服务器的情况下测试我的控制器并向localhost发送"真实"请求.我想要做的是创建请求,响应实例作为nodejs,然后只调用控制器方法.

像这样的东西:

var req = new Request()
var res = new Response()
var next = function(err) {console.log('lala')}
controller.get_user(req, res, next)
Run Code Online (Sandbox Code Playgroud)

任何建议都非常感谢.谢谢!

PS我之所以这样做的原因是最后我想测试响应对象是否包含玉视图的正确变量.

testing integration-testing mocha.js node.js express

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

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

如何在mongodb中返回更新对象的数量?

我正在更新mongodb中的多个元素.是否可以返回受影响对象的数量?

mongodb mongodb-query

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

在Javascript事件中引用的本地函数会发生什么?

我想我错过了关于javascript非常重要的事情

var gl = 10
$(document).ready(function() {
    var obj = {}
    obj.test = function() {
        gl++

        var lc = gl
        function y() {
            alert('local = ' + lc)
        }

        (function() {
            var k = lc + 1
            $('#button').click(function() {
                alert('local anonymous = ' + k)
                y()
            })                  
        })();

    }

    obj.test()
    $('#button').off()
    obj.test()          
})
Run Code Online (Sandbox Code Playgroud)

在上面的场景中,我定义了一个对象'obj',并为该对象创建了一个方法'test'.在方法内部,我有一个本地函数'y()',由附加到按钮的'click'事件使用.click事件也附加在匿名函数中.

然后我调用'test()',从按钮取消订阅'click'事件并再次调用'test()'.在结果中,我收到local = 12和local anonymous = 13.

但是我不明白javascript在内存中的作用,尤其是在每个步骤上运行'y()'和匿名函数.

我的具体问题如下,但如果您能解释整个流程,我将非常感激.

所以当我释放引用第一个'obj.test()'的所有事件时.在这种情况下,我猜这只是'点击'事件.javascript会破坏'obj.test()'范围和所有函数,包括匿名函数范围吗?我需要关心其他事情吗?

我的用例:我正在创建具有不同页面行为的动态页面加载,所以我想在全局对象方法中为每个页面分离javascript,并且一旦加载新页面,我想要分离上一页面的所有事件并调用行为功能.但是我突然意识到我并不真正理解javascript是如何工作的,并且这种方法可能存在巨大的内存泄漏.: - )

非常感谢!

javascript jquery jquery-mobile

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

Mockito - 奇怪的包范围类继承问题

发现非常有趣的问题,并在调试后发现了重现它的场景.

所以,如果我有一个包含范围B的类,它有一些公共方法,公共类A扩展它:

package somepackage;

class B {
   public void someMethod() {
      throw NullPointerException();
   }
}

package somepackage;
public class A extends B {

}
Run Code Online (Sandbox Code Playgroud)

然后在测试中:

A a = mock(A.class);
a.someMethod();
Run Code Online (Sandbox Code Playgroud)

并猜测是什么,我得到了刚刚扔的NullPointerException,所以Mockito以某种方式创建了一个"真正的"对象并调用了一个真正的方法而不是模拟的方法.为什么这样?

java.lang.IllegalArgumentException
    at test.B.setProxy(B.java:6)
    at test.A.setProxy(A.java:1)
    at secretservice.service.TestFDSServiceImpl.testService(TestFDSServiceImpl.java:17)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at …
Run Code Online (Sandbox Code Playgroud)

java unit-testing mockito

3
推荐指数
1
解决办法
617
查看次数