我有一个回调函数,before()用于清理数据库.一切都before()保证在it()开始之前完成吗?
before(function(){
db.collection('user').remove({}, function(res){}); // is it guaranteed to finish before it()?
});
it('test spec', function(done){
// do the test
});
after(function(){
});
Run Code Online (Sandbox Code Playgroud) 我有一个对象,其中所有键都是字符串,一些值是字符串,其余的是这种形式的对象:
var object = {
"fixedKey1": "something1",
"fixedKey2": "something2",
"unknownKey1": { 'param1': [1,2,3], 'param2': "some2", 'param3': 'some3'},
"unknownKey2": { 'param1': [1,2,3], 'param2': "some2", 'param3': 'some3'},
"unknownKey3": { 'param1': [1,2,3], 'param2': "some2", 'param3': 'some3'},
...
...
};
Run Code Online (Sandbox Code Playgroud)
在这个对象中fixedKey1,fixedKey2是该对象中存在的已知键.unknownKey - 值对可以从1-n变化.
我尝试将对象的接口定义为:
interface IfcObject {
[keys: string]: {
param1: number[];
param2: string;
param3: string;
}
}
Run Code Online (Sandbox Code Playgroud)
但是这会引发以下错误:
类型编号的变量不能分配类型对象
我发现它无法将此接口分配给"fixedKey - value"对.
那么,我该如何对这种变量进行类型检查呢?
我试图关注https://mochajs.org/的第一个例子
做完这个
$ npm install -g mocha
Run Code Online (Sandbox Code Playgroud)
拿到
C:\Windows\system32>npm install -g mocha
npm WARN deprecated jade@0.26.3: Jade has been renamed to pug, please install th
e latest version of pug instead of jade
npm WARN deprecated graceful-fs@2.0.3: graceful-fs version 3 and before will fai
l on newer node releases. Please update to graceful-fs@^4.0.0 as soon as possibl
e.
C:\Users\TestUser\AppData\Roaming\npm\_mocha -> C:\Users\TestUser\AppData\Roamin
g\npm\node_modules\mocha\bin\_mocha
C:\Users\TestUser\AppData\Roaming\npm\mocha -> C:\Users\TestUser\AppData\Roaming
\npm\node_modules\mocha\bin\mocha
mocha@2.4.5 C:\Users\TestUser\AppData\Roaming\npm\node_modules\mocha
??? escape-string-regexp@1.0.2
??? growl@1.8.1
??? commander@2.3.0
??? diff@1.4.0
??? supports-color@1.2.0 …Run Code Online (Sandbox Code Playgroud) 我知道我已经在某个地方见过这个解决方案,但我现在似乎无法找到它.我正在尝试查询一个MongoDB数据库,同时连接到另一个.在运行查询之前,无需显式连接到其他数据库,这是可能的.有谁知道这样做的正确语法?
我正在使用XCTest在我的项目中编写单元测试,当使用XCAssertNil()或XCAssertNotNil()方法时,XCTest框架崩溃了.
这是我的测试:
XCTAssertNotNil(messageCollection.fieldName, "field_name must be not-nil")
Run Code Online (Sandbox Code Playgroud)
这是堆栈跟踪:
2015-06-22 17:05:17.629 xctest[745:8747] *** Assertion failure in void _XCTFailureHandler(XCTestCase *, BOOL, const char *, NSUInteger, NSString *, NSString *, ...)(), /SourceCache/XCTest_Sim/XCTest-7701/XCTestFramework/OtherSources/XCTestAssertionsImpl.m:41
Test Case '-[Wakanda_iOS_Framework_Tests.WAKAdapterTest testEntityCollectionParsing]' started.
2015-06-22 17:05:17.631 xctest[745:8747] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Parameter "test" must not be nil.'
Run Code Online (Sandbox Code Playgroud)
似乎XCTest有一个名为test的参数,它不能为零,对于预期检查nil(或非nil)值的方法来说很奇怪......有没有其他人得到这个问题并解决了它?
我正在尝试在React Native中构建一个非常简单的Todo应用程序.它由两个视图组成:一个具有任务列表,一个具有输入字段(用于添加新视图).通过NavigatorIOS它上面的按钮确保导航(可以UIBarButtonItem使用UIKit).
在列表视图中,导航器上有一个添加右按钮,在带有文本字段的视图上,左侧有后退按钮,右侧有一个完成后按钮.单击"完成"时,应添加包含文本字段内容的新任务.
问题是,在创建NavigatorIOS组件时定义了按钮及其操作,我找不到将另一个组件中定义的方法作为按钮操作附加的方法.
举个例子,这是我的 NavigatorIOS
class TodoList extends Component {
render() {
return (
<NavigatorIOS
ref="nav"
style={styles.navbar}
initialRoute={{
component: ItemList,
title: 'Todo list',
rightButtonTitle: 'Add',
onRightButtonPress: () => {
this.refs.nav.push({
title: 'Add a new task',
component: AddTodo,
rightButtonTitle: 'Done',
onRightButtonPress: () => {
console.log('done !');
}
});
}
}}
/>
);
}
}
Run Code Online (Sandbox Code Playgroud)
我没有把我的另外两个组件放在这里ItemList,AddTodo因为它没有任何有趣的东西.
我需要的是一种使组件与导航组件进行通信(如委托模式)的方法.
也许这是不可能的,或者我对React Native使用的范例完全错误,所以如果我的问题不清楚,请随意评论.
编辑05/26
实际上,Facebook团队意识到缺少用NavigatorIOS组件处理该用例的东西.
来自Eric …
我已经部署到VM在GCE上运行Debian并且有使用gcloud命令的cron脚本.
我注意到这gcloud components update回复了这个错误
错误:(gcloud.components.update)此安装禁用组件管理器
我的mac可以正常更新gcloud并添加新组件.
VM映像中内置的gcloud工具不会更新.我还没有找到如何启用组件管理器.
TypeScript给了我一个编译错误,当我尝试使用我定义的React组件时,我不知道如何修复:
import App = require('./components/views/app/app');
Run Code Online (Sandbox Code Playgroud)
当我使用导入模块时,该错误消失了<any>:
import App = require('./components/views/app/app');
const App2 = App as any;
Run Code Online (Sandbox Code Playgroud)
有没有办法在一行中这样做,像这样?
import App = require('./components/views/app/app') as <any>;
Run Code Online (Sandbox Code Playgroud)
这也是导入JavaScript文件的好方法,而不必这样做:
declare module 'react-router' {
const x: any;
export = x;
}
Run Code Online (Sandbox Code Playgroud) 根据UIView.h头文件,以下方法将被弃用.
在代码中使用autolayout的替代方法是什么?
我没有看到代码注释中推荐的方法如何替换它们现有的对应物,因为它们处理实际约束而不是UIView和约束之间的关系.
@interface UIView (UIConstraintBasedLayoutInstallingConstraints)
- (NSArray *)constraints NS_AVAILABLE_IOS(6_0);
- (void)addConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead, set NSLayoutConstraint's active property to YES.
- (void)addConstraints:(NSArray *)constraints NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead use +[NSLayoutConstraint activateConstraints:].
- (void)removeConstraint:(NSLayoutConstraint *)constraint NS_AVAILABLE_IOS(6_0); // This method will be deprecated in a future release and should be avoided. Instead set NSLayoutConstraint's active property …Run Code Online (Sandbox Code Playgroud) 我使用的是instantsearch.js由Algolia提供的库.
我想要的行为是:如果访问者没有在搜索框中输入任何内容,则不会返回任何结果.
但是,Algolia 文件指出:
如果未设置查询参数,则文本搜索将与所有对象匹配.
是否可以在使用instantsearch.js时更改此行为?
这是我目前的代码:
<script type="text/javascript" src="http://cdn.jsdelivr.net/instantsearch.js/1/instantsearch.min.js"></script>
<script type="text/javascript">
window.onload = function ()
{
function getTemplate(templateName) {
return document.getElementById(templateName + '-template').innerHTML;
}
var search = instantsearch({
appId: '{{config["ALGOLIA_APPLICATION_ID"]}}',
apiKey: '{{config["ALGOLIA_API_KEY"]}}',
indexName: '{{config["ALGOLIA_INDEX_NAME"]}}',
urlSync: true
});
search.addWidget(
instantsearch.widgets.searchBox({
container: '#search-input'
})
);
search.addWidget(
instantsearch.widgets.hits({
container: '#hits-container',
hitsPerPage: 10,
templates: {
item: getTemplate('hit'),
empty: getTemplate('no-results')
}
})
);
search.start();
};
</script>
Run Code Online (Sandbox Code Playgroud) javascript ×4
ios ×3
swift ×2
typescript ×2
algolia ×1
asynchronous ×1
autolayout ×1
components ×1
deprecated ×1
gcloud ×1
mocha.js ×1
mongodb ×1
node.js ×1
npm ×1
react-native ×1
xcode ×1
xctest ×1