mirror of
https://github.com/zhigang1992/mobx-utils.git
synced 2026-06-14 01:44:54 +08:00
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
"use strict"
|
|
|
|
const utils = require("../src/mobx-utils")
|
|
const mobx = require("mobx")
|
|
|
|
mobx.configure({ enforceActions: "observed" })
|
|
|
|
test("whenWithTimeout should operate normally", done => {
|
|
var a = mobx.observable.box(1)
|
|
|
|
utils.whenWithTimeout(() => a.get() === 2, () => done(), 500, () => done.fail())
|
|
|
|
setTimeout(mobx.action(() => a.set(2)), 200)
|
|
})
|
|
|
|
test("whenWithTimeout should timeout", done => {
|
|
const a = mobx.observable.box(1)
|
|
|
|
utils.whenWithTimeout(() => a.get() === 2, () => done.fail("should have timed out"), 500, () =>
|
|
done()
|
|
)
|
|
|
|
setTimeout(mobx.action(() => a.set(2)), 1000)
|
|
})
|
|
|
|
test("whenWithTimeout should dispose", done => {
|
|
const a = mobx.observable.box(1)
|
|
|
|
const d1 = utils.whenWithTimeout(
|
|
() => a.get() === 2,
|
|
() => done.fail("1 should not finsih"),
|
|
100,
|
|
() => done.fail("1 should not timeout")
|
|
)
|
|
|
|
const d2 = utils.whenWithTimeout(
|
|
() => a.get() === 2,
|
|
() => done.fail("2 should not finsih"),
|
|
200,
|
|
() => done.fail("2 should not timeout")
|
|
)
|
|
|
|
d1()
|
|
d2()
|
|
|
|
setTimeout(
|
|
mobx.action(() => {
|
|
a.set(2)
|
|
done()
|
|
}),
|
|
150
|
|
)
|
|
})
|