У меня две функции в модуле в области видимости модуля.Одна из функций используется другой.
async function allCinemas({ puppeteer, states }) {
const cinemaDetails = [];
const page = await puppeteer
.launch({
handleSIGINT: true /*devtools: false,headless: true*/
})
.then(browser => browser.newPage());
await page.setViewport({ width: 1366, height: 735 }); //form factor - laptop/PC
await page.goto("https://www.somesite.come");
for (const state of states) {
const res = await cinemasfromState(page, state);
res.forEach(cin => {
cinemaDetails.push(cin);
});
}
await page.close();
return cinemaDetails;
}
async function cinemasfromState(page, state) {
const CINEMA_SELECTOR = `div[$[STATE]] div.top-select-option h.element`;
let res = await page.evaluate(
(elementPath, state) => {
let results = Array.from(document.querySelectorAll(elementPath)).map(
function(cin, index) {
let result = {
cinemaState: this.state,
cinemaId: cin.getAttribute("id"),
cinemaName: cin.getAttribute("name"),
};
return result;
},
{ state }
);
return [...results.reduce((a, c) => a.set(c.cinemaId, c), new Map()).values()];
},
CINEMA_SELECTOR.replace("$[STATE]", state),
state
);
return Promise.resolve(res);
}
export { allCinemas, cinemasfromState };
Я тестировал отдельно function cinemasfromState
Поэтому, когда я тестирую function allCinemas
, я думаю о заглушении function cinemasfromState
.
Как мне не заглушить / издеваться cinemasfromState
, чтобы мне не приходилось дублировать тестирование?