使用jasmine来测试其他模块中内部调用的函数?

时间:2016-04-23 09:23:53

标签: javascript unit-testing jasmine ecmascript-6

所以我有一个情况,我有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]);
});

0 个答案:

没有答案