小编jha*_*amm的帖子

试图在Angular中模拟$ http

我正在尝试为我创建的服务创建一些基本的测试覆盖率.这是我的服务:

App.factory('encounterService', function ($resource, $rootScope) {
  return {
    encounters: [],
    encountersTotalCount: 0,
    encountersIndex: 0,
    resource: $resource('/encounters/:encounterId', {encounterId:'@encounterId'}, {
      search: {
        method: 'GET',
        headers: {
          'RemoteUser': 'jjjyyy',
          'Content-Type': 'application/json'
        }
      }
    }),
    getMoreEncounters: function() {
      var that = this;
      that.resource.search({}, function(data) {
        that.encountersTotalCount = data.metadata.totalCount;
        _.each(data.encounters, function(encounter) {
          that.encounters.push(encounter);
        });
        that.busy = false;
        that.offset += 10;
        $rootScope.$broadcast('encountersFetched');
      });
    }
  };
});
Run Code Online (Sandbox Code Playgroud)

以下是我无法上班的测试:

describe('encounterService', function() {
  var _encounterService, httpBackend;
  beforeEach(inject(function(encounterService, $httpBackend) {
    _encounterService = encounterService;
    httpBackend = $httpBackend;
    var url = '/encounters/'; …
Run Code Online (Sandbox Code Playgroud)

unit-testing angularjs

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

Postgres报告关系不存在,但表存在

我有一个express应用程序,我正在连接到我的Postgres数据库.这是我的代码:

var express = require('express');
var app = express();
var pg = require('pg').native;
var connectionString = process.env.DATABASE_URL || 'postgres://localhost:5432/isx';
var port = process.env.PORT || 3000;
var client;


app.use(express.bodyParser());

client = new pg.Client(connectionString);
client.connect();

app.get('/users', function(req, res) {
  'use strict';
  console.log('/users');
  var query = client.query('SELECT * FROM users');
  query.on('row', function(row, result) {
    result.addRow(row);
  });
  query.on('end', function(result) {
    console.log(result);
    res.json(result);
  });
});
Run Code Online (Sandbox Code Playgroud)

我去当地Postgres看看isx数据库,这里有可用的表格.

          List of relations
 Schema |   Name   | Type  |  Owner   
--------+----------+-------+---------- …
Run Code Online (Sandbox Code Playgroud)

postgresql express

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

翡翠是如何工作的 - 玉

我试图使用一个Jade块,我的内容没有显示.这是我的index.jade:

//index.jade
extends ../includes/layout

block main-content
  section.content
    div(ng-view)
Run Code Online (Sandbox Code Playgroud)

它正在添加layout我期望的文件.这是该文件:

//layout.jade
doctype html
html
  head
    link(href="/favicon.ico", rel="shortcut icon",type="image/x-icon")
    link(rel="stylesheet", href="/css/bootstrap.css")
    link(rel="stylesheet", href="/vendor/toastr/toastr.css")
    link(rel="stylesheet", href="/css/site.css")
  body(ng-app="app")
    h1 Hello Worldd
    include scripts
Run Code Online (Sandbox Code Playgroud)

但它不包括我的main.jade:

// main.jade
h1 This is a Partial
h2 {{ myVar }}
Run Code Online (Sandbox Code Playgroud)

或其后的任何代码.这是我第一次使用,Jade所以我很挣扎.另外,-content当你包括一个时,它是block什么?谢谢.

pug

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

如何从VirtualBox命中修改的/ etc/hosts

我有一个应用程序,我必须更改/etc/hosts文件才能命中.这是我的新文件.

#127.0.0.1      localhost
127.0.0.1       local.connectwithme
Run Code Online (Sandbox Code Playgroud)

这在我的本地机器上很容易.我只是local.connectwithme:3000在我的浏览器中,我能够查看我的应用程序.

我现在正试图通过VirtualBox运行来查看它Windows 7.通常我只是去10.0.2.2虚拟机浏览器中的ip地址并localhost从中访问我的主机VirtualBox,但是现在我已经更改了/etc/hosts主机上的文件我不知道我需要点什么才能看到我的应用程序在虚拟机上.有人可以向我解释一下.谢谢.

virtualbox hosts

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

居中弹性项目,行末尾有一个

我正在创建一个导航栏flexbox.这是我的html:

<div class="container">
    <div>Project</div>
    <div>About the Project</div>
    <div>Contact Us</div>
    <div>Mailbox</div>
</div>
Run Code Online (Sandbox Code Playgroud)

我的css:

.container {
  display: flex,
  justify-content: center
}
Run Code Online (Sandbox Code Playgroud)

这是目前的样子:

当前的Navbar

我想要mailbox div在结束时flex container.我希望它看起来更像这样.

想要导航栏

我试过flex-end这个弹性项目无济于事.我需要做些什么来实现这一目标?

html css css3 flexbox

5
推荐指数
2
解决办法
7402
查看次数

为什么Java Calendar会说本月的第一个星期四是第5周?

我想弄清楚如何在一周的特定日期发出警报.这是打印我期望的示例代码:

  Calendar calendar = Calendar.getInstance();
  calendar.set(Calendar.WEEK_OF_MONTH, 1);
  System.out.println("Week of month: " + calendar.get(Calendar.WEEK_OF_MONTH)); // Week of month: 1
Run Code Online (Sandbox Code Playgroud)

但是,当我将其添加到代码中时,我得到的结果我不明白:

  Calendar calendar = Calendar.getInstance();
  calendar.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
  calendar.set(Calendar.WEEK_OF_MONTH, 1);
  System.out.println("Week of month: " + calendar.get(Calendar.WEEK_OF_MONTH)); // Week of month: 5
Run Code Online (Sandbox Code Playgroud)

我试图在特定的一周内为特定日期设置警报.今天的日期是2013年6月15日.有人可以向我解释一下.Joda时间不是我正在做的选择,所以我需要使用常规Java库来完成这项工作.谢谢你的帮助.

编者注

上面的代码将根据运行日期返回不同的结果,因为Calendar.getInstance()将Calendar设置为当前时间.有关与当前时间无关的问题的说明,请使用以下命令:

DateFormat dateFormat = DateFormat.getDateInstance();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(1371294000000L);
System.out.println(dateFormat.format(calendar.getTime()));
calendar.set(Calendar.DAY_OF_WEEK, Calendar.THURSDAY);
System.out.println(dateFormat.format(calendar.getTime()));
calendar.set(Calendar.WEEK_OF_MONTH, 1);
System.out.println("Week of month: " + calendar.get(Calendar.WEEK_OF_MONTH)); 
System.out.println(dateFormat.format(calendar.getTime()));
Run Code Online (Sandbox Code Playgroud)

哪个输出这样的东西(至少如果您的默认语言环境使用公历):

Jun 15, 2013
Jun 13, 2013
Week of month: 5
May 30, 2013
Run Code Online (Sandbox Code Playgroud)

java calendar

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

Android - notifyDataSetChanged()不起作用

我创建了一个显示问题列表的自定义ArrayAdapter.我查询数据库,转换该数据,将数据传递给数组,然后将数组传递给ArrayAdapter以显示我的列表.

dbData = getDbData();
List<Question> questions = getQuestions(1L);
dbData.closeDb();
setContentView(R.layout.activity_questions);
adapter = new QuestionsAdapter(this, getCurrentContext(), questions, 1L, dbData);
Run Code Online (Sandbox Code Playgroud)

在我的应用程序中,您可以单击各种问题,操作一些东西并返回主列表.底层数组尚未更改,因为更改已在db中保留.我再次查询数据库,运行我的转换,然后我的数组是最新的.我在我的onResume()方法中执行此操作,但适配器将无法识别该notifyDataSetChanged()方法的任何更改.我onResume()看起来像这样:

@Override
protected void onResume() {
    super.onResume();
    dbData = getDbData();
    questions = getQuestions(1L);
    adapter = new QuestionsAdapter(this, getCurrentContext(), questions, 1L, dbData);
    items.setAdapter(adapter);
}
Run Code Online (Sandbox Code Playgroud)

我必须查询数据库,进行转换,创建我的数组,然后为我的更改创建一个新的适配器以显示在主列表中.为什么我不能这样做:

@Override
protected void onResume() {
    super.onResume();
    dbData = getDbData();
    questions = getQuestions(1L);
    adapter.notifyDataSetChanges();
}
Run Code Online (Sandbox Code Playgroud)

我需要做些什么来完成这项工作?谢谢您的帮助.

java android android-arrayadapter

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

为什么我的变量在我的Jasmine测试中未定义 - Jasmine.js

我已经开始为我的js文件编写测试,而且我得到了一个undefined我没想到的地方.这是我的代码:

describe('show jasmine testing', function() {
  var x;
  beforeEach(function() {
    x = 3;
  });

  describe('booleans', function() {
    it('should return true', function() {
      expect(true).toBe(true);
    });
  });

  describe('ints', function() {
    console.log('This is x: ' + x);
    expect(x).toBe(3);
  });
});
Run Code Online (Sandbox Code Playgroud)

在我的ints测试中,我的x变量是undefined,所以测试总是失败.根据我的理解应该是3因为beforeEach块在每个describe块之前运行.我错过了什么?

javascript jasmine

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

为什么这个组件从受控切换到不受控制? - 反应

这是我的无状态反应组件:

export default ({acresMin, update}) => (
    <div>
        <input
            onChange={(e) => update({'acresMin': e.target.value})}
            placeholder="10"
            type="text"
            value={acresMin}/>
    </div>
)
Run Code Online (Sandbox Code Playgroud)

当我更改中的值时input,我得到这个warning:

Warning: StatelessComponent is changing an uncontrolled input of type text to be controlled. Input elements should not switch from uncontrolled to controlled (or vice versa). Decide between using a controlled or uncontrolled input element for the lifetime of the component.

我正在使用a更新onChange并保存store正在填充的值props.

我怎么不理解这个?

reactjs redux

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

如何在节点中使用 fetch 发出 http 请求?节点获取

我正在尝试在节点中发出请求。这是我的代码:

fetch("http://www.test.com", options).catch(err => {
    console.error(err);

    return err;
  });
Run Code Online (Sandbox Code Playgroud)

这是我得到的错误。 TypeError: Only HTTP(S) protocols are supported

我尝试创建一个新代理并将其传递到如下选项中:

const httpAgent = new http.Agent({
    keepAlive: true
});
const httpsAgent = new https.Agent({
    keepAlive: true
});

const options = {
    agent: function (_parsedURL) {
        if (_parsedURL.protocol == 'http:') {
            return httpAgent;
        } else {
            return httpsAgent;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

我仍然遇到同样的错误。

当我在客户端中运行它时,我可以向客户端发送一个http或一个请求,并且没有问题。显然它在节点上是不同的。httpsfetch

处理这个问题的最佳方法是什么?

fetch node.js

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