Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
似乎使用 Mocha 设置任何方法调用期望会阻止调用原始实现。
这似乎涵盖了使用 rspec 调用原始方法。
有没有办法用摩卡做到这一点?或者有谁知道为什么不支持这个?
由于几个原因,这是不可能的。一个原因是测试方法的副作用和测试方法的调用可以在两个单独的测试中更清楚地完成。我读到的另一个原因是,在纯粹的单元测试中,您不会断言另一种方法的副作用。您将测试调用,然后在该特定方法的单元测试中测试被调用方法的副作用。