我在单元测试方面遇到问题。当我运行测试时,它最终以"No tests found". 我正在使用AppCode和Quick/Nimble框架进行单元测试,但它在 XCode 中也不起作用。
我已经XCTest/Kiwi使用“目标:MyAppTests”、“配置:开发”和“类:所有测试类”运行配置(即使指定了特定测试类,它也不起作用)。据我所知,没有什么更多的配置。
有什么想法我做错了吗?我不确定我应该提供什么其他类型的信息/配置..谢谢
编辑:示例单元测试代码
import Quick
import Nimble
@testable import FigurePOS
class DateFormatterTest: QuickSpec
{
override func spec()
{
describe("formatting dates") {
it("should print correct date") {
var c = DateComponents()
c.year = 2016
c.month = 5
c.day = 24
c.hour = 4
c.minute = 33
c.second = 12
let gregorian = NSCalendar(identifier: .gregorian)!
let date = gregorian.date(from: c)!
expect(DateFormatter.formatGmt(date)).to(equal("2016-05-24T04:33:12Z"))
}
}
}
}
Run Code Online (Sandbox Code Playgroud) 我有一个内部有 Switch 组件的组件。整个组件都是可点击的。当您单击此组件时,它会触发调度(修改 redux 存储)并导致此组件重新渲染。我需要的是不重新渲染整个组件,而只是将该 Switch 组件动画化到正确的状态。
像这样的东西
<TouchableOpacity onPress={onPress}>
<Text>{this.props.title}</Text>
<Switch value={this.state.active}/>
</TouchableOpacity>
Run Code Online (Sandbox Code Playgroud)
任何想法?
我发现这个非常常见的用例,并且我知道我会遇到很多类似的场景,所以我需要这种行为,但我在网络上找不到任何示例或解决方案。也许我只是错过了一些东西。
谢谢
- - 编辑 - -
我也尝试过这个。我尝试使用 shouldComponentUpdate 禁用更新,我尝试仅在 willRecieveProps 和/或切换中设置状态,即使没有切换。我也尝试过使用 LayoutAnimation。但没有任何效果。this.setState() 只是不会为 Switch 组件设置动画。我也尝试使用 this._switch._rctSwitch.setNativeProps({ value: nextProps.active }) 但这也不起作用(并且由于 _rctSwitch 而闻起来很臭)。
class ViewWithSwitchInside extends React.Component {
constructor(props) {
super(props)
this.toggle = this.toggle.bind(this);
this.state = {
active: props.active
}
}
componentWillReceiveProps(nextProps) {
if (this.state.active != nextProps.active) {
this.setState({ active: nextProps.active })
}
}
toggle() {
let newValue = !this.state.active
this.setState({
active: newValue,
})
if …Run Code Online (Sandbox Code Playgroud) 因为在最新的redux-observable(0.17)中直接调用了store.dispatch(),所以如果我需要从redux app外部调度动作,我想知道什么是替代方法.
例:
假设我有这个函数初始化本机模块并设置本机处理程序.
const configure = (dispatch) => {
const printingModule = NativeModules.PrintingManager
const eventEmitter = new NativeEventEmitter(printingModule)
eventEmitter.addListener(
"PrintingManagerNewPrinterConnected",
(payload) => dispatch({
type: PRINTER_MANAGER_NEW_PRINTER_CONNECTED,
payload: {
macAddress: payload[2],
connectionType: payload[3],
},
}))
printingModule.initialize()
}
Run Code Online (Sandbox Code Playgroud)
我通常做的是在APP_STARTUP_FINISHED之后我会从observable调用这个函数:
const appStatePrepared = (action$: Object, { dispatch }) =>
action$.ofType(APP_STATE_PREPARED)
.switchMap(() => {
configurePrinters(dispatch)
})
Run Code Online (Sandbox Code Playgroud)
对此有什么正确的解决方案?
谢谢!
非常简单和常见的用例,但我找不到令人满意的答案。我有反应本机应用程序,需要在本地存储一些数据。我正在使用redux和redux-observables和Realm作为存储。
我需要的是:发生一些操作,比方说ADD_ITEM。我需要使用一些有效负载(标准Redux)更新UI。然后,我想创建/将有效负载转换为另一段数据,并将该数据(异步)保存到Realm中。无论我尝试什么,它总是滞后于UI(很多)。
我试图将领域调用包装到promise中并使用switchMap,但是它仍然很慢。
我还没有看过工作程序,但是他们只接受字符串,这对我来说有用得多。
我可以将计算完全卸载到本机后台线程,但这会非常不舒服,并且会花费很多时间。
异步可以帮助我吗?redux-saga?我觉得这是同一回事,不是真正的异步处理。
还是我为此使用完全错误的库?
const insertOrderItem = (action$) =>
action$.ofType(Action.ADD_ORDER_ITEM)
.switchMap(({ payload }) => Rx.Observable.fromPromise(
new Promise((resolve, reject) => {
storage.insert(createObject(payload)
resolve({
type: "OPERATION_ADDED"
})
})
))
Run Code Online (Sandbox Code Playgroud)
通常,将少量数据存储到领域中不会带来太多的计算量,但我觉得有必要在后台线程上进行此类工作。
我想念什么吗?
谢谢
asynchronous background-process realm react-native redux-observable
react-native ×2
redux ×2
animation ×1
appcode ×1
asynchronous ×1
ios ×1
quick-nimble ×1
react-redux ×1
reactjs ×1
realm ×1
swift ×1
unit-testing ×1