如果我有
class ErrorThrower{
void throwAnError(String argument){
throw new Error();
}
}
Run Code Online (Sandbox Code Playgroud)
我想测试 throwAnError 是否抛出异常,或者更准确地说是一个 Error
这是我的代码,但它不起作用
test('', () {
var errorThrower = new ErrorThrower();
expect(errorThrower.throwAnError("string"), throwsException);
});
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用 firestore 为我的应用程序添加持久性。看起来不错,但我在路上遇到了一个颠簸,谷歌搜索似乎让我失望。我认为这可能比 firestore更像是一个飞镖问题,所以请根据您的需要进行编辑!
基本上我有类似以下的情况:
class attributes(){
double xpos, ypos;
String id;
}
class item(){
String name;
int price;
List<attributes> attributeHistory;
Map<String, dynamic> toMap(){
Map<String, dynamic> returnMap = new Map();
returnMap['name'] = name;
returnMap['price'] = price;
returnMap['attributeHistory'] = //what goes here??;
}
}
Run Code Online (Sandbox Code Playgroud)
那么......那里有什么?我已经为属性编写了一个 .toMap 函数,但我不知道这让我在哪里!
有任何想法吗?
我的常规单元测试与我的服务放在文件夹中
现在我创建了一个名为的新文件夹integration/,在这个文件夹中我的所有测试看起来都是这样的anotherFolder/testSomeApi.integration.js
我这样做了,这样当我调用 时node jest,它会运行所有单元测试,但不运行集成测试。我想使用单独的命令从我的 docker 容器调用集成测试
我怎样才能调用类似的东西,jest *integration.js以便integration.js调用带有扩展名的集成文件夹中的所有测试?
集合在 Firebase 控制台上具有默认权限。
我使用电子邮件和密码正确登录我的用户。
user = await _auth.signInWithEmailAndPassword(
email: "email@gmail.com", password: "password");
然后在将图像成功上传到 FireStorage 后,我也尝试运行一个事务来更新文档。
var fileName = _textController.text.toLowerCase();
StorageUploadTask putFile =
storage.ref().child("region/$fileName").putFile(_regionImage);
UploadTaskSnapshot uploadSnapshot = await putFile.future;
var regionData = new Map();
regionData["label"] = _textController.text;
var pictureData = new Map();
pictureData["url"] = uploadSnapshot.downloadUrl.toString();
pictureData["storage"] = "gs://app-db.appspot.com/region/$fileName";
regionData["picture"] = pictureData;
DocumentReference currentRegion =
Firestore.instance.collection("region").document(fileName);
Firestore.instance.runTransaction((transaction) async {
DocumentSnapshot freshSnap = await transaction.get(currentRegion);
print(freshSnap.exists);
//await transaction.set(freshSnap.reference, regionData);
await transaction.set(currentRegion, regionData);
print("instance created");
});
Run Code Online (Sandbox Code Playgroud)
尝试运行事务时出现此错误。
如果我尝试设置为freshSnap.reference或直接设置为currentRegion.
https://gist.github.com/matejthetree/f2a57c929d01919bd46da8ca6d5b6fb1
请注意,在第 …
我编写了许多await用于处理的异步代码Futures。
如果我有
() async {
var result = await someFuture();
}
Run Code Online (Sandbox Code Playgroud)
捕获错误的首选方式是什么。在try / catch或执行中包装代码
() async {
var result = await someFuture().catch(_errorHandler);
}
Run Code Online (Sandbox Code Playgroud)
编辑:
另外,如果我在一个异步方法中有许多等待调用,则首选捕获所有错误,而不是.catchError为每个错误编写。
() async {
var result = await someFuture();
var result2 = await someFuture2();
var result3 = await someFuture3();
}
Run Code Online (Sandbox Code Playgroud) 通常 a 的密钥Widget是var key = GlobalKey<WidgetState>私有TextFormFieldState的。由于我只有一种文本形式,因此我避免将其包装在Form. 能做到吗?
我有一个在端口 4000 上提供 http 服务的容器。它附加了套接字服务器
docker-撰写:
dashboard-server:
image: enginetonic:compose1.2
container_name: dashboard-server
command: node src/service/endpoint/dashboard/dashboard-server/dashboard-server.js
restart: on-failure
ports:
- 4000:4000
integration-test:
image: enginetonic:compose1.2
container_name: integration-test
testRegex "(/integration/.*|(\\.|/)(integration))\\.jsx?$$"
tty: true
Run Code Online (Sandbox Code Playgroud)
服务器:
const http = require('http').createServer(handler)
const io = Io(http)
io.on('connection', socket => {
logger.debug('socket connected')
})
io.use((socket, next) => {
logger.debug('socket connection established.')
})
http.listen(4000, '127.0.0.1', () => {
console.log(
`Server running at http://127.0.0.1:4000/`
)
Run Code Online (Sandbox Code Playgroud)
泊坞窗中的输出:
Server running at http://127.0.0.1:4000/
https is listening: true
现在,我尝试从另一个容器连接到该服务器,如下所示:
文件:
const url = `ws://dashboard-server:4000`
const ioc …Run Code Online (Sandbox Code Playgroud) 我正在尝试 codelabs firebase 集成教程。
https://codelabs.developers.google.com/codelabs/flutter-firebase/
我完成了所有步骤 <= 步骤 6 配置 firebase 和本地应用程序,但是在运行应用程序后它崩溃了。控制台没有错误,这是控制台日志:
https://gist.github.com/anonymous/564bd94e1e0f90548f3d7a9882699874
我只为 iOS 配置了应用程序,而不是为 android 配置应用程序,我在 iOS 模拟器中运行该应用程序。也许它会有所作为。
如何在地图上进行迭代,逐个删除元素,然后在删除每个元素后调用一个函数?
假设我有发布功能
final HashMap<int, bool> _instances = new HashMap<int, bool>();
void release(dynamic instance) {
if (_instances[instance.hashCode] != null) {
_releaseHashCode(instance.hashCode);
_dispatcher.dispatchEvent(PinEvent.release);
}
}
void _releaseHashCode(int hashCode) => _instances.remove(hashCode);
Run Code Online (Sandbox Code Playgroud)
现在我想创建releaseAll()将调用_releaseHashCode地图中的每个元素,从而释放它并调度释放事件。
void releaseAll() {
...
}
Run Code Online (Sandbox Code Playgroud) 在Firestore中设置基本类型非常容易。
但是我找不到如何使用Flutter Firestore插件构造Geopoint,Timestamp和其他文档参考。
您如何对设置Map<String,dynamic>为每个对象的默认数据进行内部分析?
任何帮助或例子吗?
我想在文本中写一个$符号
Text("Refer and Win 10 000 $")
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
写这个的正确方法是什么?