Skip to content

Commit

Permalink
More stable tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Kim Almasan committed Jun 17, 2020
1 parent 84c3183 commit 9c6bd8c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 57 deletions.
12 changes: 6 additions & 6 deletions test/browser.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
/* global expect, beforeAll, afterAll */
import webdriver, { By, ThenableWebDriver, until } from 'selenium-webdriver'
import chrome from 'selenium-webdriver/chrome'
import { elementIsVisible, elementLocated } from 'selenium-webdriver/lib/until'

const sleep = (x: number) => new Promise(resolve => setTimeout(resolve, x))

const options = new chrome.Options()
options.addArguments(
Expand Down Expand Up @@ -106,12 +103,13 @@ describe('browser', () => {
await driver.wait(until.elementLocated(By.css('.click-test')))
const el = await driver.findElement(By.css('.click-test')).click()
await driver.wait(untilRemoved('.click_test', driver))
const day = await driver.findElement(By.css(`[data-date="1144447200000"]`))
await driver.wait(until.elementLocated(By.css('.dp-day')))
const day = await driver.findElement(By.css(`.dp-day`))
await day.click()
await driver.wait(untilRemoved('.dp-modal', driver))
const val = await driver.findElement(By.css('.click-test')).getAttribute('value')

expect(val).toEqual('4/8/2006')
expect(val).toEqual('3/26/2006')
})

it('should show the prev month when prev arrow is clicked', async () => {
Expand Down Expand Up @@ -218,6 +216,7 @@ describe('browser', () => {
`)
await driver.wait(until.elementLocated(By.css('.my-modal')), 2000, 'could not find expected modal on page!')
await driver.findElement(By.css('.my-modal')).click()
await driver.wait(until.elementLocated(byText('17')))
await driver.findElement(byText('17')).click()
await driver.wait(untilRemoved('.dp-modal', driver))

Expand Down Expand Up @@ -309,8 +308,9 @@ describe('browser', () => {
`)
const el = await driver.findElement(By.css('.modal-txt'))
await el.click()
await driver.wait(elementIsVisible(driver.findElement(byText('May'))))
await driver.wait(until.elementLocated(byText('May')))
await driver.findElement(byText('May')).click()
await driver.wait(until.elementLocated(byText('February')))
await driver.findElement(byText('February')).click()

const current = await currentEl(driver, '.dp-modal')
Expand Down
85 changes: 34 additions & 51 deletions test/fns.test.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,37 @@
/* global expect */
import {bufferFn} from '../src/lib/fns';
import { bufferFn } from '../src/lib/fns'

const sleep = (x: number) => new Promise(resolve => setTimeout(resolve, x))

describe('bufferFn', () => {
it('only runs once within a window of time', () => {
return new Promise((resolve, reject) => {
let count = 0;
const f = bufferFn(1, () => ++count);

f();
f();
f();

expect(count).toEqual(0);

setTimeout(() => {
try {
expect(count).toEqual(1);
resolve();
} catch (err) {
reject(err);
}
}, 5);
});
});

it('only runs twice if called outside of the window', () => {
return new Promise((resolve, reject) => {
let count = 0;
const f = bufferFn(1, () => ++count);

f();
f();
f();

expect(count).toEqual(0);

setTimeout(() => {
f();
f();
f();
}, 10);

setTimeout(() => {
try {
expect(count).toEqual(2);
resolve();
} catch (err) {
reject(err);
}
}, 15);
});
});
});
it('only runs once within a window of time', async () => {
let count = 0
const f = bufferFn(100, () => ++count)

f()
f()
f()

await sleep(200)
expect(count).toBe(1)
})

it('only runs twice if called outside of the window', async () => {
let count = 0
const f = bufferFn(100, () => ++count)

f()
f()
f()

await sleep(200)
expect(count).toBe(1)

f()
f()
f()

await sleep(200)
expect(count).toBe(2)
})
})

0 comments on commit 9c6bd8c

Please sign in to comment.