Skip to content

Commit

Permalink
Merge pull request #259 from mobxjs/fix-flaky-observable-stream-tests
Browse files Browse the repository at this point in the history
test/observable-stream.ts: Double timeouts to prevent tests flaking out
  • Loading branch information
NaridaL committed May 24, 2020
2 parents e08275d + 30dfe7d commit 394a4ae
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions test/observable-stream.ts
Expand Up @@ -61,40 +61,40 @@ test("to observable - should not push the initial value", () => {

test("from observable", (done) => {
mobx.configure({ enforceActions: "observed" })
const fromStream = utils.fromStream(interval(10), -1)
const fromStream = utils.fromStream(interval(20), -1)
const values: number[] = []
const d = mobx.autorun(() => {
values.push(fromStream.current)
})

setTimeout(() => {
expect(fromStream.current).toBe(-1)
}, 5)
}, 10)
setTimeout(() => {
expect(fromStream.current).toBe(0)
}, 15)
}, 30)
setTimeout(() => {
expect(fromStream.current).toBe(1)
fromStream.dispose()
}, 25)
}, 50)
setTimeout(() => {
expect(fromStream.current).toBe(1)
expect(values).toEqual([-1, 0, 1])
d()
mobx.configure({ enforceActions: "never" })
done()
}, 35)
}, 70)
})

test("from observable with initialValue of a different type", async () => {
mobx.configure({ enforceActions: "observed" })
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))

const fromStream = utils.fromStream(interval(10), "start")
const fromStream = utils.fromStream(interval(20), "start")
const values: (number | string)[] = []
const stopAutorun = mobx.autorun(() => values.push(fromStream.current))

await sleep(35)
await sleep(70)
expect(fromStream.current).toBe(2)
expect(values).toEqual(["start", 0, 1, 2])
fromStream.dispose()
Expand Down

0 comments on commit 394a4ae

Please sign in to comment.