Skip to content

πŸ“ˆ Get real-time stocks from TradingView

Fix a test (2)

Mathieu Colmond7e244880224
diff --git a/tests/simpleChart.test.ts b/tests/simpleChart.test.ts
index 971e018..4ff2a68 100644
--- a/tests/simpleChart.test.ts
+++ b/tests/simpleChart.test.ts
@@ -23,7 +23,7 @@ describe('Simple chart session', async () => {
while (
chart.infos.full_name !== 'BINANCE:BTCEUR'
- || !chart.periods.length
+ || chart.periods.length < 10
) await utils.wait(100);
expect(chart.infos.full_name).toBe('BINANCE:BTCEUR');
@@ -39,7 +39,7 @@ describe('Simple chart session', async () => {
console.log('Setting timeframe to 15 minutes...');
chart.setSeries('15');
- while (!chart.periods.length) await utils.wait(100);
+ while (chart.periods.length < 10) await utils.wait(100);
console.log('Chart timeframe set');
expect(
diff --git a/tests/utils.ts b/tests/utils.ts
index 9ecd81a..549585f 100644
--- a/tests/utils.ts
+++ b/tests/utils.ts
@@ -5,13 +5,11 @@ export const wait = (ms: number) => (
export function calculateTimeGap(periods: { time: number }[]) {
let minTimeGap = Infinity;
- for (let i = 1; i < 10; i += 1) {
- const time1 = periods[i - 1]?.time;
- const time2 = periods[i]?.time;
- if (!time1 || !time2) continue;
-
- const timeGap = time1 - time2;
- if (timeGap < minTimeGap) minTimeGap = timeGap;
+ for (let i = 1; i < periods.length; i += 1) {
+ minTimeGap = Math.min(
+ minTimeGap,
+ periods[i - 1].time - periods[i].time,
+ );
}
return minTimeGap;