Support promise return in ospec

This commit is contained in:
Stephan Hoyer 2017-08-04 09:23:20 +02:00
parent 7ab6eb2ba0
commit b345e4f023
3 changed files with 111 additions and 21 deletions

View file

@ -107,7 +107,7 @@ o.spec("ospec", function() {
o(output).deepEquals({tag: "div", children: children})
})
})
o.spec("async", function() {
o.spec("async callback", function() {
var a = 0, b = 0
o.before(function(done) {
@ -148,4 +148,47 @@ o.spec("ospec", function() {
})
})
})
o.spec("async promise", function() {
var a = 0, b = 0
function wrapPromise(fn) {
return new Promise(resolve => {
callAsync(() => {
fn()
resolve()
})
})
}
o.before(function() {
return wrapPromise(() => {
a = 1
})
})
o.after(function() {
return wrapPromise(function() {
a = 0
})
})
o.beforeEach(function() {
return wrapPromise(function() {
b = 1
})
})
o.afterEach(function() {
return wrapPromise(function() {
b = 0
})
})
o("promise functions", async function() {
await wrapPromise(function() {
o(a).equals(b)
o(a).equals(1)("a and b should be initialized")
})
})
})
})