我试图找出如何使用FsUnit正确测试异常.官方文档指出,要测试异常,我必须这样:
(fun () -> failwith "BOOM!" |> ignore) |> should throw typeof<System.Exception>
Run Code Online (Sandbox Code Playgroud)
但是,如果我没有用[<ExpectedException>]属性标记我的测试方法,它将始终失败.听起来很合理,因为如果我们想测试异常,我们必须在C#+ NUnit中添加这样的属性.
但是,只要我添加了这个属性,我试图抛出什么样的异常并不重要,它将始终处理.
一些片段:我的LogicModule.fs
exception EmptyStringException of string
let getNumber str =
if str = "" then raise (EmptyStringException("Can not extract number from empty string"))
else int str
Run Code Online (Sandbox Code Playgroud)
我的LogicModuleTest.fs
[<Test>]
[<ExpectedException>]
let``check exception``()=
(getNumber "") |> should throw typeof<LogicModule.EmptyStringException>
Run Code Online (Sandbox Code Playgroud) 我刚刚将我的React应用程序更新为16.6.0并将反应脚本更新为2.0.3以开始使用懒惰,并且在关注官方文档的示例时出现此错误:
失败的道具类型:提供component的类型的无效道具,预期objectRoutefunction
忽略它一切似乎都有效,除了控制台中的这个错误.
这是我的一些代码:
// imports here
...
const Decks = lazy(() => import('./pages/Decks'));
...
class App extends Component {
...
render() {
return (
<ConnectedRouter history={history}>
<div>
<MenuAppBar />
<div style={{paddingTop: '4rem'}}>
<Suspense fallback={<LazyLoading />}>
<Switch>
<Route exact path="/" component={Home} />
<Route path="/decks" component={Decks} />
...
</Switch>
</Suspense>
</div>
<Footer />
</div>
</ConnectedRouter>
);
}
Run Code Online (Sandbox Code Playgroud)
...}
我在这里做错了什么?
我有一个本地C库,我想用它做一些F#编码.事情是我得到例外:
System.TypeLoadException:无法编组"LoggingModel"类型的字段"log":此类型没有编组支持.
在System.StubHelpers.ValueClassMarshaler.ConvertToNative(IntPtr dst,IntPtr src,IntPtr pMT,CleanupWorkList&pCleanupWorkList)
的FSI_0009.Initialize(ComponentOverrideFlags标志,LoggingModel&loggingModel,ThreadingModel&threadingModel,SchedulingModel&schedulingModel,IntPtr memoryModel)
at.$ FSI_0011.main @()在D:\ dev_p\f#\ FunBindings\FunExample\Environment.fs:第16行由于错误而停止
这里的代码:
module Interop
[<CLSCompliant(true); Flags>]
type LogTarget =
| None = 0
| Console = 1
| Trace = 2
| Custom = 4
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type LogCallback = delegate of LogTarget * string * string * nativeint -> unit
[<UnmanagedFunctionPointer(CallingConvention.Cdecl)>]
type ReleaseCallback = delegate of nativeint -> unit
[<Struct>]
type LoggingModel =
val mutable targets : LogTarget
val mutable log : LogCallback
val mutable deleteModel : …Run Code Online (Sandbox Code Playgroud) 如何从raphael中的对象中删除动画?
var animation = Raphael.animation({opacity:.2}, 1000);
var circle = paper.circle(0, 0, 5).animate(animation.repeat(Infinity));
Run Code Online (Sandbox Code Playgroud)
我想在对象上执行动画,直到某个时刻.问题是如何在特定时刻删除/停止动画?