我试图测试此模块(receiver.js)是否抛出错误:
var request = require('request')
module.exports = function(url){
request({
url: url,
method: 'POST'
}, function(error) {
if(error){
throw error
}
})
}
Run Code Online (Sandbox Code Playgroud)
使用此测试(test.js):
var test = require('tape')
test('Receiver test', function(t){
var receiver = require('./receiver')
t.throws(function(){
receiver('http://localhost:9999') // dummy url
}, Error, 'Should throw error with invalid URL')
t.end()
})
Run Code Online (Sandbox Code Playgroud)
但是磁带在抛出错误之前运行断言,导致以下错误消息:
TAP version 13
# Receiver test
not ok 1 Should throw error with invalid URL
---
operator: throws
expected: |-
[Function: Error]
actual: |-
undefined
at: Test.<anonymous> (/path/to/tape-async-error-test/test.js:5:4)
...
/path/to/receiver.js:9 …Run Code Online (Sandbox Code Playgroud) 首先使用 Web API 2 和 EF 6.1 代码。
我正在尝试添加一个Template与现有TimePeriods和Stations.
public class Template
{
public int TemplateID { get; set; }
public string Name { get; set; }
public List<TimePeriod> TimePeriods { get; set; }
public List<Station> Stations { get; set; }
}
public class Station
{
public int StationID { get; set; }
public string Name { get; set; }
public List<Template> Templates { get; set; }
}
public class TimePeriod
{
public int …Run Code Online (Sandbox Code Playgroud) 当从函数中检索多个返回时,我得到你可以通过使用:=或者通过简单地使用将值分配给已存在的变量来动态地声明值的变量=.当我想要为现有变量分配一个返回值,同时为另一个声明一个新变量时,我的问题出现了.
我目前只通过分配值并bar预先声明所需的变量(在本例中)来解决它,就像在这个片段中一样:
package main
import (
"fmt"
)
func getFooAndBar() (foo string, bar string) {
return "Foo", "Bar"
}
func main() {
var foo = "default"
var condition = true
if condition {
var bar string // Would like to avoid this step if possible
foo, bar = getFooAndBar()
fmt.Println(bar)
}
fmt.Println(foo)
}
Run Code Online (Sandbox Code Playgroud)
如果我使用:=它由于以下原因而无法构建:
./app.go:16:foo声明并且未使用
那么,是否有可能以某种方式避免bar单独声明的步骤?