简体   繁体   中英

Must extract functions in module to use spy/stub/mock with sinon.js

Saying I have this file index.js :

export const f = () => 5;
export const g = () => f();

And my index-spec.js :

import * as F from './index'
const spy = sinon.spy(F, 'f')
F.g()
assert(F.f.calledOnce)

This code will not work, but I don't understand the reason. If I extract f in another module the code will work.

Can somebody save me! :) Thanks

Your code is not invoking function f. Change Fg() to Ff()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM