siesta-lite
Version:
Stress-free JavaScript unit testing and functional testing tool, works in NodeJS and browsers
134 lines (105 loc) • 3.49 kB
JavaScript
StartTest(function(t) {
t.it('`throwsOkAsync` should correctly pass', function (t) {
document.body.innerHTML = '<div onclick="foobar()" id="el" class="some-button">Some text</div>'
var done
t.chain(
function (next) {
done = t.throwsOkAsync('foobar', 'Correct exception thrown')
next()
},
// the exception is expected from the click handler
{ click : '.some-button' },
function (next) {
done()
next()
}
)
})
t.it('`throwsOkAsync` should correctly pass', function (t) {
var done
t.chain(
function (next) {
done = t.throwsOkAsync('foo')
Promise.resolve().then(() => {
throw new Error('foo')
})
setTimeout(next, 100)
},
function (next) {
done()
next()
}
)
})
t.it('`throwsOkAsync` should correctly fail', function (t) {
t.expectFail(function(t) {
document.body.innerHTML = '<div id="el" class="some-button">Some text</div>'
var done
t.chain(
function (next) {
done = t.throwsOkAsync('foobar', 'Correct exception thrown', 1000)
next()
},
// the exception is expected from the click handler
{ click : '.some-button' },
function (next) {
done()
next()
}
)
})
})
t.it('`livesOkAsync` should correctly pass', function (t) {
document.body.innerHTML = '<div id="el" class="some-button">Some text</div>'
var done
t.chain(
function (next) {
done = t.livesOkAsync('No exception thrown')
next()
},
// the exception is expected from the click handler
{ click : '.some-button' },
function (next) {
done()
next()
}
)
})
t.it('`livesOkAsync` should correctly fail', function (t) {
t.expectFail(function(t) {
document.body.innerHTML = '<div onclick="foobar()" id="el" class="some-button">Some text</div>'
var done
t.chain(
function (next) {
done = t.livesOkAsync('No exception thrown')
next()
},
// the exception is expected from the click handler
{ click : '.some-button' },
function (next) {
done()
next()
}
)
})
})
t.it('`livesOkAsync` should correctly fail', function (t) {
t.setExceptionHandlerOverrideFlag(true)
t.expectFail(function(t) {
var done
t.chain(
function (next) {
done = t.livesOkAsync('Should change dependency type')
Promise.resolve().then(() => {
throw new Error('foo')
})
setTimeout(next, 100)
},
function (next) {
done()
next()
}
)
})
})
})