所以我有一个情况,我有2个模块,为了参数,我们称它们为A和B.
模块A:
import C from './C';
import { shuffle } from './B';
const A_func = () => new C(shuffle([1, 2, 3, 0]));
export default A_func;
模块B:
...
export const shuffle = (array) => {
// knuth shuffle algorithm
// return the shuffled array
};
...
// there are other exports as well
export shuffle;
我想测试模块A,但我想监视模块B导出的shuffle方法。
A.spec.js
describe('A', () => {
// no Idea how to create spy on shuffle
// would like to return a predetermind array as output of shuffle
// let's say [2, 3, 1, 0]
// something like (which won't work)
// spOn('shuffle').and.returnValue([2, 3, 1, 0]);
});