小编Cri*_*ens的帖子

无法在使用 Jest、Supertest、Passport、Koa2 的测试中再次发送经过身份验证的请求

我一直在尝试使用 internetross's March 2018 的答案,但无济于事。我也使用 Jest、Supertest,就我而言,还使用 ​​Koa 和 Passport。

在 Visual Studio 中使用 REST 客户端,没问题。会话通过,Passport 进行身份验证,然后我获取数据。但在玩笑中,不行。我可以正常登录,我得到 Koa:sess 正常,但我无法发出经过身份验证的请求。

有人看到下面的内容吗?

const supertest = require('supertest')
const app = require('../app.js')
const http = require('http')

const agent = supertest.agent((http.createServer(app.callback())))

let session = null

beforeAll(async () => {
  const response = await agent
  .post('/v1/users/login')
  .set({'content-Type': 'application/json'})
  .send({ username: 'username', password: 'password' })

  session = response.headers['set-cookie'][0]
               .split(',')
               .map(item => item.split(';')[0])
               .join('; ')

  console.log(stringify(session))

  expect(response.status).toEqual(200)
})

describe('user tests', () => {
  test('data', async () => { …
Run Code Online (Sandbox Code Playgroud)

node.js supertest jestjs koa2

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

如何从外部排序功能更新ng-grid

任何人都知道如何从外部排序功能更新ng-grid?

我已将userExternalSort设置为true.然后,我有这个代码(Coffeescript):

$scope.$on 'ngGridEventSorted', (event, data) ->
    console.log "Before sort " + $scope.recs[0].location

    $scope.recs.sort (a, b) ->
        if data.directions[0] = "asc"
            return a.location > b.location ? 1 : -1
        else
            return a.location > b.location ? -1 : 1

    console.log "After sort " + $scope.recs[0].location
Run Code Online (Sandbox Code Playgroud)

我的功能实际上排序.但是,ng-grid永远不会更新.我已经尝试了$ scope.$ apply()无济于事 - 它已经在$ apply中了.

谢谢.

angularjs ng-grid

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

使用chrome.runtime.sendmessage从网页到打包的应用程序进行通信

我正在尝试从网页到打包的应用程序进行通信.想法是让网页从串行设备读取数字.因为我想访问串行设备,我需要一个打包的应用程序,不能使用扩展.这与Keep Chrome Packaged App在后台运行非常相似似乎Chrome文档说这是可能的.

如何从常规网页执行chrome.runtime.sendMessage?当我这样做时,我得到*Uncaught TypeError:无法读取未定义的属性'sendMessage'.我的简单功能是:

function doFunction(){
    chrome.runtime.sendMessage(editorExtensionId, {openUrlInEditor: url},
      function(response) {
        if (!response.success)
          handleError(url);
      });
}
Run Code Online (Sandbox Code Playgroud)

我的打包应用程序加载并可以访问串行端口.但我的怀疑是清单不是"启用"常规网页的chrome.runtime.manifest.json的:

{
  "name": "Hello World!",
  "description": "My first Chrome App.",
  "version": "0.1",
  "app": {
    "background": {
      "scripts": ["background.js"]
    }
  },
  "icons": { "16": "calculator-16.png", "128": "calculator-128.png" },
  "permissions": [
    "serial",
    "*://localhost/*"
  ],
  "externally_connectable": {
  "matches": [
      "*://localhost/*"]
}
}
Run Code Online (Sandbox Code Playgroud)

也许它是:// localhost /我正在用于测试.但Chrome并没有抱怨.

有什么想法吗?提前致谢.

google-chrome google-chrome-app

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